Added a QuerySet.ordered property to check if a queryset is already ordered. Refs #10163.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10623 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2009-04-22 22:16:19 +00:00
parent d463580c1b
commit c00e8d2064
3 changed files with 50 additions and 0 deletions

View file

@ -615,7 +615,24 @@ class QuerySet(object):
clone = self._clone()
clone.query.add_immediate_loading(fields)
return clone
###################################
# PUBLIC INTROSPECTION ATTRIBUTES #
###################################
def ordered(self):
"""
Returns True if the QuerySet is ordered -- i.e. has an order_by()
clause or a default ordering on the model.
"""
if self.query.extra_order_by or self.query.order_by:
return True
elif self.query.default_ordering and self.query.model._meta.ordering:
return True
else:
return False
ordered = property(ordered)
###################
# PRIVATE METHODS #
###################