Answer the question
In order to leave comments, you need to log in
How to annotate/aggregate with calculated fields?
For a long time I have been suffering from a lack of understanding of one simple thing - how to aggregate the property fields of a model?
Example:
class MyModel(models.Model):
title = models.CharField('Название', max_length=100, unique=True)
@property
def test(self):
return self.pk
queryset.annotate(lol_kek=Sum('test')).lol_kek
Answer the question
In order to leave comments, you need to log in
test is not a field in the database, but a method in the django model. On it it will not turn out to do aggregation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question