code: def aggregate(self, *args, **kwargs):
          
          if self.query.distinct_fields:
              raise NotImplementedError("aggregate() + distinct(fields) not implemented.")
          for arg in args:
              # The default_alias property may raise a TypeError, so we use
              # a try/except construct rather than hasattr in order to remain
              # consistent between PY2 and PY3 (hasattr would swallow
              # the TypeError on PY2).
              try:
                  arg.default_alias
              except (AttributeError, TypeError):
                  raise TypeError("Complex aggregates require an alias")
              kwargs[arg.default_alias] = arg
  
          if django.VERSION < (2, 0):
              query = self.query.clone(CTEAggregateQuery)
          else:
              query = self.query.chain(CTEAggregateQuery)
          for (alias, aggregate_expr) in kwargs.items():
              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(self.db, kwargs.keys())
docs: Returns 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.