自定义库存表(Stock)
class Stock(models.Model):
amount = amount = models.IntegerField(verbose_name='数量')
price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='单价')
使用模板语法完成自定义查询:
Stock.objects.annotate(profit=F('price')*F('amount')).order_by('-profit')
—— 实现了以将所有库存总价格(单价*数量)由高到低的查询出来
标签:总价,自定义,models,查询,乘以,amount,Django,Stock From: https://www.cnblogs.com/wellplayed/p/18016553