Search code examples
djangodjango-modelsdjango-admin

How to show all model fields in the admin page?


Here is a screenshot of the models page: enter image description here

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

def __unicode__(self):
    return self.title;  

Here is each individual object: enter image description here

How do I show all these fields? How do I show all the fields in each Model page?


Solution

  • 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)