如何在字段集中显示Django管理内嵌模型? [英] How can I display a Django admin inline model within a fieldset?

查看:139
本文介绍了如何在字段集中显示Django管理内嵌模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的ModelAdmin。在这种情况下,我希望在无字段集和备注字段集之间显示内联书UI。这是可能的吗?

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆