MCPcopy
hub / github.com/tortoise/tortoise-orm / annotate

Method annotate

tortoise/queryset.py:627–641  ·  view source on GitHub ↗

Annotate result with aggregation or function result. :raises TypeError: Value of kwarg is expected to be a ``Function`` instance.

(self, **kwargs: Expression | Term)

Source from the content-addressed store, hash-verified

625 return self
626
627 def annotate(self, **kwargs: Expression | Term) -> QuerySet[MODEL]:
628 """
629 Annotate result with aggregation or function result.
630
631 :raises TypeError: Value of kwarg is expected to be a ``Function`` instance.
632 """
633 from tortoise.models import get_filters_for_field
634
635 queryset = self._clone()
636 for key, annotation in kwargs.items():
637 # if not isinstance(annotation, (Function, Term)):
638 # raise TypeError("value is expected to be Function/Term instance")
639 queryset._annotations[key] = annotation
640 queryset._custom_filters.update(get_filters_for_field(key, None, key))
641 return queryset
642
643 def group_by(self, *fields: str) -> QuerySet[MODEL]:
644 """

Callers

nothing calls this directly

Calls 4

_cloneMethod · 0.95
get_filters_for_fieldFunction · 0.85
itemsMethod · 0.80
updateMethod · 0.80

Tested by

no test coverage detected