将来自其他模型的字段添加到admin内联-Django admin

时间:2019-03-11 22:18:25

标签: python django

考虑一下:

@admin.register(MyModel)
MyModelAdmin(admin.ModelAdmin):

    fieldsets = [
        ('Field1', {'fields': ['field1']}),
        ('Field2', {'fields': ['field2']}),
        ...
        ]
    list_display = ('field1', 'field2')

假设我的管理员有另一个模型:

@admin.register(AnotherModel)
AnotherModelAdmin(admin.ModelAdmin):

    fieldsets = [
        ('Field1', {'fields': ['field3']}),
        ('Field2', {'fields': ['field4']}),
        ...
        ]
    list_display = ('field3', 'field4')

因此,我需要将field3中的AnotherModelAdmin显示为MyModelAdmin内联。

我该如何实现?

0 个答案:

没有答案