在中删除或编辑对象名称表格管理员

2024-10-04 09:31:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我在管理中的表格内联如下所示:

tabularinline

我如何摆脱DateDeCotisation_adherents object短语?在

对于加分,为什么底部有三条空线?在

管理员py在

class DatesDeCotisationInline(admin.TabularInline):
    model = DateDeCotisation.adherents.through
    readonly_fields = ['datedecotisation']
    can_delete = False

模型.py在

^{pr2}$

Tags: pyfieldsmodelobjectadmin管理员class表格
1条回答
网友
1楼 · 发布于 2024-10-04 09:31:43

内联应该从模型according to the documentation的内部Meta类中获取verbose_name和{}。但是,我刚刚将您的代码转储到最新的django中,它实际上没有(或者,也许,只有当您使用.through时它才这样做)。在

幸运的是,您可以通过直接在InlineModelAdmin中设置verbose_name和{}来覆盖它,即

class DatesDeCotisationInline(admin.TabularInline):
    model = DateDeCotisation.adherents.through
    readonly_fields = ['datedecotisation']
    can_delete = False
    verbose_name = 'date de cotisation for adherent'
    verbose_name_plural = 'date de cotisation for adherent'

class AdherentAdmin(admin.ModelAdmin):
    inlines = [DatesDeCotisationInline]

admin.site.register(models.Adherent, AdherentAdmin)

(很抱歉这里的“for”,但我不会说法语)

admin在Django 1.10中显示如下:

django tabular inline


请注意,在Python3中,您永远不需要执行.encode('utf-8')。默认情况下,它的刺是UTF-8。在

^{pr2}$

(我假设您使用的是python3,因为您使用的是__str__

相关问题 更多 >