我需要在django admin中使用内联线来显示两个模型之间的关系,但在我这样做的时候,我不得不使用反向关系来显示内联线
例如:
class OtherModel(models.Model):
field1=models...
........
class Model(models.Model)
field1 = models....
other_model = models.ForeignKey(OtherModel)
我创建内联
class OtherModelInline(admin.StackedInline):
model = OtherModel
extra = 1
@admin.register(Model):
class ModelAdmin(admin.modelAdmin):
inlines = [OtherModelInline]
所以。。。 当我在OtherModel上创建内联时,它需要外键。。 我如何在不改变关系的情况下展示这一点
这是正确的做法
如果要使用内联线,则需要指定这两个模型在某种程度上是相关的
相关问题 更多 >
编程相关推荐