如何保存()新值?
错误: AttributeError:“int”对象没有属性“保存”
我有这个代码:
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'