diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-10-15 15:52:18 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-10-16 09:27:20 +0200 |
| commit | 374c14b7fd8a7ba06cebfa83dd40915a50796d3e (patch) | |
| tree | 3b95404984198c5ad330add30e4d50b52dde4676 /django/db | |
| parent | 947af46db3c285edd3679106d374b258d491ecb8 (diff) | |
Fixed #23659 -- Kept annotate() args ordering
Thanks Loic Bistuer and Simon Charette for the review.
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/models/query.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index 9371aa14e0..6dbca8369a 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -2,7 +2,7 @@ The main QuerySet implementation. This provides the public API for the ORM. """ -from collections import deque +from collections import deque, OrderedDict import copy import sys import warnings @@ -786,27 +786,29 @@ class QuerySet(object): Return a query set in which the returned objects have been annotated with data aggregated from related fields. """ + aggrs = OrderedDict() # To preserve ordering of args for arg in args: if arg.default_alias in kwargs: raise ValueError("The named annotation '%s' conflicts with the " "default name for another annotation." % arg.default_alias) - kwargs[arg.default_alias] = arg + aggrs[arg.default_alias] = arg + aggrs.update(kwargs) names = getattr(self, '_fields', None) if names is None: names = set(self.model._meta.get_all_field_names()) - for aggregate in kwargs: + for aggregate in aggrs: if aggregate in names: raise ValueError("The annotation '%s' conflicts with a field on " "the model." % aggregate) obj = self._clone() - obj._setup_aggregate_query(list(kwargs)) + obj._setup_aggregate_query(list(aggrs)) # Add the aggregates to the query - for (alias, aggregate_expr) in kwargs.items(): + for (alias, aggregate_expr) in aggrs.items(): obj.query.add_aggregate(aggregate_expr, self.model, alias, is_summary=False) |
