i grouped by a value then sum of a field , but now i want to only summation happen if a column inside annotate
greater that or equal to 1 !
my models.py
class MyModel(models.Model):
name = models.ForeignKey(Product, on_delete=models.CASCADE)
order = models.IntegerField()
price = models.IntegerField()
class Prodcut(models.Model):
name = models.CharField(max_lenth=20)
cost = models.IntegerField()
price = models.IntegerField()
this is my query
MyModel.objects.values('name__name').annotate(
income=(
Sum(((F('price')*F('order')) - (
(F('name__price')+F('name__cost'))*F('order'))
),output_field=IntegerField())),quantity=(
Sum(F('order'))
))
sometimes happen income smaller than 0 (negative values) , i dont want summation of those products which their incomes smaller than 0 , i want to use something like this inside the annotate
or Sum
income__gte=1
!? ,
i have some more
fields i dont want to use .filter
at the end of )annotate
is it possible only add to income column if the new income greater than or equal to 1?