gpt4 book ai didi

django - 如何在字段集中显示 Django 管理内联模型?

转载 作者:行者123 更新时间:2023-11-28 19:37:42 27 4
gpt4 key购买 nike

考虑以下 ModelAdmin。在这种情况下,我希望在“无”字段集和注释字段集之间显示内联“书籍”UI。这可能吗?

class AuthorAdmin(admin.ModelAdmin):
inlines = [BookInline]

fieldsets = (
(None, {
'fields': ('author_name', 'date_of_birth')
}),
('Notes', {
'fields': (['notes'])
}),
)

最佳答案

Bertrand Bortage 在这里发布了另一个解决方案:https://groups.google.com/forum/#!topic/django-users/yUq2Nvx_4eM

A late reply to say that I just pushed a fairly clean solution to this problem in one of my projects: https://github.com/dezede/dezede/commit/ed13ccaf34494e71fd913fd785c229052f6acdc8.

The idea is to define fieldsets_and_inlines_order in your ModelAdmin(s), an iterable of 'f' and 'i' characters (for "fieldset" and "inline") that specifies the order between the first fieldsets and inlines. If len(fieldsets_and_inlines_order) < len(fieldsets) + len(inlines), the remaining follows the original behaviour (fieldsets first, then all inlines).

Example: you have 5 fieldsets and 3 inlines, defining fieldsets_and_inlines_order = ('f', 'f', 'i', 'f', 'i') will give you: fieldset fieldset inline fieldset inline fieldset fieldset inline Hope it helps, Bertrand

我有另一个值得考虑的想法。在您的字段集中为每个内联创建一个只读占位符字段,然后使用 jQuery 将内联移动到每个占位符的位置。像这样的东西(jQuery 省略了,因为我还没有写它):

fieldsets = (
(None, {
'fields': (
('inline_images',)
('thumbnail_image',),
('inline_authors',)
('title', 'is_active', 'order',)
),
}),
)

readonly_fields = ('inline_images', 'inline_authors')

inline_images = '<span class="replaceme inline_images"></span>'
inline_images.allow_tags = True
inline_authors = '<span class="replaceme inline_authors"></span>'
inline_authors.allow_tags = True

还有一件事 - 有一个 Unresolved Django 问题要求内联的这种定位:https://code.djangoproject.com/ticket/4848

关于django - 如何在字段集中显示 Django 管理内联模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18390627/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com