23.3.1 Configuring the List of Post Objects

Instead of letting the admin app generate PostAdmin for us through a call to site.register(), we can instead use the @register() decorator on a subclass of ModelAdmin, allowing us to configure the set of admin pages using expected attributes. To begin, we can set the list_display attribute, defining which fields in PostAdmin we want displayed, as shown in Example 23.6. Figure 23.6 shows the result of this change.

Example 23.6: Project Code

blog/admin.py in 14e2d2282b

6   @admin.register(Post) 7   class PostAdmin(admin.ModelAdmin): 8       list_display = ('title', 'pub_date')

Figure 23.6: Post List in 14e2d2282b

This change has no effect on the add page, shown in ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.