我有一个django模型,包含多个字段,如下所示:
class Sponsor(CommonInfo, Person):
signature_code = models.CharField(max_length=20, blank=True)
account = models.ForeignKey(Account)
department = models.ForeignKey(Department)
product = models.ManyToManyField(Product, null=True, blank=True, through = 'ProductSponsor')
accounts = models.ManyToManyField(Account, null=True, blank=True, through = 'AccountSponsor', related_name='sponsoraccounts')
我的观点有:
class SponsorEdit(UpdateView):
model = Sponsor
template_name = 'sponsoredit.html'
fields = ('account', 'department', 'exp_date', 'last_name', 'first_name', 'signature_code', 'comments', 'product', 'accounts')
当我通过在Many to MAny关系中添加一些字段来编辑条目时,我收到以下错误:
AttributeError at /irms/sponsoredit/2
Cannot set values on a ManyToManyField which specifies an intermediary model. Use irms.ProductSponsor's Manager instead.
问题出在哪里?
答案 0 :(得分:0)
在您的模型中,您使用的是function setCellValue(cellName, value) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var cell = sheet.getRange(cellName);
cell.setValue(value);
}
setCellValue("A1","Approved");
和AccountSponsor
。它们是关系的自定义中间表,当您保存ProductSponsor
对象时,需要手动设置中间“Sponsor
”和“ProductSponsor
”对象。类似的东西:
AccountSponsor