How to show all fields of model in admin page?

后端 未结 11 514
無奈伤痛
無奈伤痛 2021-01-30 16:25

here is the models page

In this picture, only the title shows up on here, I used:

 def __unicode__(self):
        return self.title;  

11条回答
  •  说谎
    说谎 (楼主)
    2021-01-30 16:49

    By default, the admin layout only shows what is returned from the object's unicode function. To display something else you need to create a custom admin form in app_dir/admin.py.

    See here: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display

    You need to add an admin form, and setting the list_display field.

    In your specific example (admin.py):

    class BookAdmin(admin.ModelAdmin):
        list_display = ('title', 'author', 'price')
    admin.site.register(Book, BookAdmin)
    

提交回复
热议问题