Skip to content

Instantly share code, notes, and snippets.

@ychennay
Created March 22, 2020 06:29
Show Gist options
  • Save ychennay/1c5404c1f55ff9d97a900f21d5a0c5c9 to your computer and use it in GitHub Desktop.
Save ychennay/1c5404c1f55ff9d97a900f21d5a0c5c9 to your computer and use it in GitHub Desktop.
class QuerySet:
"""Represent a lazy database lookup for a set of objects."""
# ...
@property
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
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment