Django Admin两次显示主键列

时间:2016-04-06 13:43:25

标签: django django-models django-templates django-admin django-views

我正在使用Django Admin,这显示了我想编辑的每个字段。但是,如果我也选择主键作为可编辑键,Django Admin会将此字段显示两次。第一个(用于检查是否要删除它)和最后一个相同的列(在所有列之后)再次使用主键但没有列的标题。 如何在不丢失此主键的可编辑选项的情况下避免使用此最后一列?

编辑:

--Admin.py--
class table_nameAdmin(admin.ModelAdmin):
list_display = ['field1','field2',]
list_editable = ['field1','field2',]
search_fields = ['field1',]
ordering = ('field2',)
list_per_page = records_Per_Page

admin_site.register(table_name,table_nameAdmin)

Django Admin模板如下所示:

|name_Field1  ||name_Field2            ||no_name                |
-----------------------------------------------------------------
|values_field1||values_field2_editables||values_field1_editables|

我可以只显示两个字段作为可编辑的内容吗?

1 个答案:

答案 0 :(得分:1)

您可以尝试删除第一列“链接”以编辑页面。 像这样:

class table_nameAdmin(admin.ModelAdmin):
    list_display = ['field1','field2',]
    list_editable = ['field1','field2',]
    search_fields = ['field1',]
    ordering = ('field2',)
    list_per_page = records_Per_Page

    def __init__(self, *args, **kwargs):
        super(table_nameAdmin, self).__init__(*args, **kwargs)
        self.list_display_links = (None, )