MCPcopy
hub / github.com/django/django / aggregate

Method aggregate

django/db/models/query.py:615–638  ·  view source on GitHub ↗

Return a dictionary containing the calculations (aggregation) over the current queryset. If args is present the expression is passed as a kwarg using the Aggregate object's default alias.

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

613 yield item
614
615 def aggregate(self, *args, **kwargs):
616 """
617 Return a dictionary containing the calculations (aggregation)
618 over the current queryset.
619
620 If args is present the expression is passed as a kwarg using
621 the Aggregate object's default alias.
622 """
623 if self.query.distinct_fields:
624 raise NotImplementedError("aggregate() + distinct(fields) not implemented.")
625 self._validate_values_are_expressions(
626 (*args, *kwargs.values()), method_name="aggregate"
627 )
628 for arg in args:
629 # The default_alias property raises TypeError if default_alias
630 # can't be set automatically or AttributeError if it isn't an
631 # attribute.
632 try:
633 arg.default_alias
634 except (AttributeError, TypeError):
635 raise TypeError("Complex aggregates require an alias")
636 kwargs[arg.default_alias] = arg
637
638 return self.query.chain().get_aggregation(self.db, kwargs)
639
640 async def aaggregate(self, *args, **kwargs):
641 return await sync_to_async(self.aggregate)(*args, **kwargs)

Callers 15

get_facet_querysetMethod · 0.80
date_hierarchyFunction · 0.80
_save_tableMethod · 0.80
test_col_alias_quotedMethod · 0.80
test_max_pkMethod · 0.80
test_unionMethod · 0.80
test_extentMethod · 0.80
test_extent3d_filterMethod · 0.80
test_cast_aggregateMethod · 0.80

Calls 4

get_aggregationMethod · 0.80
valuesMethod · 0.45
chainMethod · 0.45

Tested by 15

test_col_alias_quotedMethod · 0.64
test_max_pkMethod · 0.64
test_unionMethod · 0.64
test_extentMethod · 0.64
test_extent3d_filterMethod · 0.64
test_cast_aggregateMethod · 0.64
test_collectMethod · 0.64
test_extentMethod · 0.64