class Item(models.Model):
name = models.CharField(max_length=50)
item_price = models.DecimalField(max_digits=5, decimal_places=2)
class Magazine(models.Model):
name = models.CharField(max_length=50)
items = models.ManyToManyField('Item', blank=True, null=True)
owner = models.ForeignKey(User, related_name='u_item')
如何获得杂志中所有物品的价格总和?
在意见中:
...
user = request.user
magazins = Magazine.objects.filter(owner= user)
...