mirror of
https://github.com/django/django.git
synced 2025-09-27 12:39:17 +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:
parent
d463580c1b
commit
c00e8d2064
3 changed files with 50 additions and 0 deletions
|
@ -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 #
|
||||
###################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue