Skip to content

Instantly share code, notes, and snippets.

Created Mar 22, 2020
What would you like to do?
class QuerySet:
"""Represent a lazy database lookup for a set of objects."""
# ...
def ordered(self):
Return True if the QuerySet is ordered -- i.e. has an order_by()
clause or a default ordering on the model (or is empty).
if isinstance(self, EmptyQuerySet):
return True
if self.query.extra_order_by or self.query.order_by:
return True
elif self.query.default_ordering and self.query.get_meta().ordering:
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment