新しい値をsave()する方法は?
エラー: AttributeError:'int'オブジェクトに属性'save'がありません
私はこのコードを持っています:
class Magazin(models.Model):
owner = models.ForeignKey(User, related_name='user_magazin', verbose_name='Owner')
name = models.CharField("Magazin_Name", max_length=30)
products = models.ManyToManyField('Product', through='MagazinProduct', blank=True, null=True)
class MagazinProduct(models.Model):
product = models.ForeignKey('Product')
magazin = models.ForeignKey('Magazin')
quantity = models.IntegerField()
私はこのようなことを試みます:
from magazin.product.models import *
In [2]: user = 2 #user id
In [3]: quantity = 4
In [4]: magazin = Magazin.objects.get(owner=user)
In [6]: mp = MagazinProduct.objects.get(magazin=magazin, product=1) #product=1 this is ID
In [8]: mp.quantity
Out[8]: 1
In [9]: mp.quantity = quantity
In [10]: mp.quantity
Out[10]: 4
In [11]: mp.quantity.save()
---------------------------------------------------------------------------
AttributeError: 'int' object has no attribute 'save'