Answer the question
In order to leave comments, you need to log in
How to combine a queryset with a calculated field (which is created based on the same queryset)?
Model manager
class DairyManager(models.Manager):
def get_queryset(self):
return super(DairyManager, self).get_queryset().extra(select={'totalsum':'count*cost'})
class Dairy(models.Model):
...
count = models.IntegerField("Количество")
cost = models.FloatField('Цена')
...
total = DairyManager()
objects = models.Manager()
qs1 = Dairy.total.all()
qs2 = Dairy.objects.all()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question