mirror of
https://github.com/django/django.git
synced 2025-10-29 00:26:07 +00:00
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:
@@ -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 #
|
||||
###################
|
||||
|
||||
Reference in New Issue
Block a user