別の問題があります。それを修正する方法は?私はDjangoの初心者です。
私のエラー:
/magazines/のAttributeError'Magazine'オブジェクトには属性'items_set'がありません
class Item(models.Model):
name = models.CharField(max_length=50)
item_price = models.DecimalField(max_digits=5, decimal_places=2)
class Magazine(models.Model):
items = models.ManyToManyField('Item', blank=True, null=True)
owner = models.ForeignKey(User, related_name='u_item')
def show(request): #magazines items and total price of all items in this magazine
user = request.user
magazines = Magazine.objects.filter(owner=user)
for m in Magazine.objects.filter(owner=user):
total = m.items_set.all().annotate(total=Sum('item_price'))
print 'Total cost for items in {0} is {1}'.format(m,total)
return render_to_response('magazines.html', {'magazines': magazines, 'total': total})