我有一个报价模型,其中将quoteitems作为相关字段。
class BusinessQuote(models.Model):
id = models.AutoField(primary_key=True)
client = models.ForeignKey(BusinessClient, null=True, on_delete=models.SET_NULL)
site = models.ForeignKey(BusinessSite, null=True, on_delete=models.SET_NULL)
...
和
class BusinessQuoteitem(models.Model):
id = models.AutoField(primary_key=True)
quote = models.ForeignKey(BusinessQuote, null=True, on_delete=models.CASCADE)
job = models.ForeignKey(BusinessJobtask, blank=True, null=True, on_delete=models.SET_NULL)
ordered = models.IntegerField(default=0)
...
它们在管理员中以内联方式显示
class InlineQuoteItems(admin.TabularInline):
model = BusinessQuoteitem
extra = 0
formfield_overrides = { ... }
class QuoteAdmin(admin.ModelAdmin):
list_display = ['id', 'date', 'client', 'site', 'tradename', 'total', 'converted']
list_filter = ['tradename', 'client', ]
inlines = [InlineQuoteItems]
admin.site.register(BusinessQuote,QuoteAdmin)
当我尝试删除嵌入式项目时,出现以下错误:
Exception Type: TypeError
Exception Value: %d format: a number is required, not NoneType
Exception Location: /home/.../business/models.py in __str__, line 237
第237行涉及:
def __str__(self):
return "%d" % (self.id)
令人困惑的是,这通常可以解决问题,所以我对导致内联删除失败的原因不知所措。
我在提交之前对字段进行了一些JavaScript处理,以总计内联项并更新了发票总额,但是它不涉及id字段,并且作为客户端,我看不到它具有影响力。