【发布时间】:2011-08-30 18:09:49
【问题描述】:
这是我的模特
class Business(models.Model):
business_type = models.ManyToManyField(BusinessType)
establishment_type = models.ForeignKey(EstablishmentType)
website = models.URLField()
name = models.CharField(max_length=64)
def __unicode__(self):
return self.name
在我看来,我正在尝试按如下方式保存记录:
business = BusinessForm(request.POST or None)
if business.is_valid():
busi = business.save(commit=False)
bt = BusinessType.objects.get(id=6)
busi.business_type = bt
et = EstablishmentType.objects.get(id=6)
busi.establishment_type = et
busi.save()
但是,它给了我一个错误
'Business' instance needs to have a primary key value before a many-to-many relationship can be used.
如何保存?
【问题讨论】:
标签: django django-models django-views