示例#1
0
 def get_with_total(cls):
     # запрос, так быстрее
     total_output_field = models.DecimalField(max_digits=10,
                                              decimal_places=2)
     total_expr = E(F('amount') * F('product__price'),
                    output_field=total_output_field)
     return cls.objects.annotate(total=total_expr)
示例#2
0
 def order_value(self):
     queryset = self.salesorderitem_set.aggregate(order_value=Sum(
         E(F('unit_price') * F('quantity_ordered'),
           output_field=models.DecimalField())), )
     return queryset['order_value'] or 0
示例#3
0
 def get_with_total(cls):
     total_output_field = models.DecimalField(max_digits=10,
                                              decimal_places=2)
     total_expr = E(F('qty') * F('products__price'),
                    output_field=total_output_field)
     return cls.objects.annotate(total=total_expr)