mirror of
https://github.com/django/django.git
synced 2025-11-30 07:19:08 +00:00
Fixed #24060 -- Added OrderBy Expressions
This commit is contained in:
parent
f48e2258a9
commit
21b858cb67
9 changed files with 310 additions and 54 deletions
|
|
@ -1691,14 +1691,14 @@ class Query(object):
|
|||
"""
|
||||
Adds items from the 'ordering' sequence to the query's "order by"
|
||||
clause. These items are either field names (not column names) --
|
||||
possibly with a direction prefix ('-' or '?') -- or ordinals,
|
||||
corresponding to column positions in the 'select' list.
|
||||
possibly with a direction prefix ('-' or '?') -- or OrderBy
|
||||
expressions.
|
||||
|
||||
If 'ordering' is empty, all ordering is cleared from the query.
|
||||
"""
|
||||
errors = []
|
||||
for item in ordering:
|
||||
if not ORDER_PATTERN.match(item):
|
||||
if not hasattr(item, 'resolve_expression') and not ORDER_PATTERN.match(item):
|
||||
errors.append(item)
|
||||
if errors:
|
||||
raise FieldError('Invalid order_by arguments: %s' % errors)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue