如何在字段集中显示Django管理内嵌模型? [英] How can I display a Django admin inline model within a fieldset?
问题描述
class AuthorAdmin(admin.ModelAdmin):
inlines = [BookInline]
fieldsets =(
(无,{
'fields':('author_name','date_of_birth')
}),
('Notes',{
'fields':(['notes'])
}),
)
不幸的是,这是不可能的(django的标准模板)。如果您查看change_form的模板,您可以看到inline在字段集之后总是单独呈现:
https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/change_form.html
我看到的唯一解决方法是根据您想要的顺序编写自定义模板。
Consider the following ModelAdmin. In this instance, I'd like to have the inline "Book" UI display between the "None" fieldset and the Notes fieldset. Is that possible?
class AuthorAdmin(admin.ModelAdmin):
inlines = [BookInline]
fieldsets = (
(None, {
'fields': ('author_name', 'date_of_birth')
}),
('Notes', {
'fields': (['notes'])
}),
)
Unfortunately this is not possible with (the standard template from) django. If you look at the template for the change_form, you can see that inlines are always rendered separately after the fieldset: https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/change_form.html
The only work-around I see is to write a custom template with respect to the order you want.
这篇关于如何在字段集中显示Django管理内嵌模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!