mirror of
https://github.com/django/django.git
synced 2025-09-23 02:33:31 +00:00
Fixed #23875 -- cleaned up query.get_count()
This commit is contained in:
parent
87bd13617c
commit
c7fd9b242d
3 changed files with 33 additions and 96 deletions
|
@ -335,12 +335,11 @@ class QuerySet(object):
|
|||
kwargs[arg.default_alias] = arg
|
||||
|
||||
query = self.query.clone()
|
||||
force_subq = query.low_mark != 0 or query.high_mark is not None
|
||||
for (alias, aggregate_expr) in kwargs.items():
|
||||
query.add_annotation(aggregate_expr, self.model, alias, is_summary=True)
|
||||
query.add_annotation(aggregate_expr, alias, is_summary=True)
|
||||
if not query.annotations[alias].contains_aggregate:
|
||||
raise TypeError("%s is not an aggregate expression" % alias)
|
||||
return query.get_aggregation(using=self.db, force_subq=force_subq)
|
||||
return query.get_aggregation(self.db, kwargs.keys())
|
||||
|
||||
def count(self):
|
||||
"""
|
||||
|
@ -824,7 +823,7 @@ class QuerySet(object):
|
|||
if alias in names:
|
||||
raise ValueError("The annotation '%s' conflicts with a field on "
|
||||
"the model." % alias)
|
||||
obj.query.add_annotation(annotation, self.model, alias, is_summary=False)
|
||||
obj.query.add_annotation(annotation, alias, is_summary=False)
|
||||
# expressions need to be added to the query before we know if they contain aggregates
|
||||
added_aggregates = []
|
||||
for alias, annotation in obj.query.annotations.items():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue