Django list_editable()无法显示主键值

时间:2016-06-04 07:32:12

标签: python django

我是Django的新手。我尝试在Django管理页面中显示不同的字段,并找到在页面中显示详细信息的选项。我确信list_display_links有效,但我在尝试list_editable时收到错误。有人能指出错误的原因吗?

class SaleAdmin(admin.ModelAdmin):
    list_editable = ["pk","product_id","old_price","new_price","discount_start","discount_end","store_id","created"]
    list_display = ["pk","product_id","old_price","new_price","discount_start","discount_end","store_id","created"]
    list_display_links = ["pk","product_id","old_price","new_price","discount_start","discount_end","store_id","created"]

    class Meta:
        model = Sale
    def store_id(self, instance):
        return instance.store_id.id

    def product_id(self, instance):
        return instance.product_id.name

错误:

django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
<class 'dataInfo.admin.SaleAdmin'>: (admin.E121) The value of 'list_editable[0]' refers to 'pk', which is not an attribute of 'dataInfo.Sale'.

1 个答案:

答案 0 :(得分:0)

错误消息抱怨此部分

list_editable = ["pk", "product_id","old_price", ...

将其更改为“id”。

list_editable = ["id", "product_id","old_price", ...

更好的是,从该列表中删除pk / id,因为您很可能不想编辑主键。