1
我有以下的模型和TabularInline子類:Django管理TabularInline抱怨缺少現場
class SomeModel(models.Model):
name = models.CharField(max_length=50)
class SomeModelInline(admin.TabularInline):
model = SomeModel
class SomeOtherModelAdmin(admin.ModelAdmin):
inlines = [SomeModelInline]
沒有明確指定TabularInline的田地,Django的管理顯示的字段「ID」和「名稱」。然而,當我嘗試這樣做:
class SomeModelInline(admin.TabularInline):
model = SomeModel
fields ['id','name']
的Django拋出ImproperlyConfigured異常:
'SomeModelInline.fields' refers to field 'id' that is missing from the form.
這是怎麼回事?爲什麼我不能明確指定id,即使Django顯然能夠訪問它?
這不是真的是我問,但它確實讓我來解決此問題。 – Cerin