I am new to Django. I try to display different fields in Django admin page and find to options to display details in the page. I am sure that list_display_links
works,but I get error when I try list_editable
. Can someone points out the reason of error?
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
Error:
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'.
The error message complains about this part
list_editable = ["pk", "product_id","old_price", ...
Change it to "id".
list_editable = ["id", "product_id","old_price", ...
Better yet, remove pk
/ id
from that list, because you most likely do not want to edit the primary key.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.