Performance: Admin customization with ModelAdmin
MEDIUM IMPACT
This affects the admin interface load time and responsiveness by controlling how data is queried and displayed.
class BookAdmin(admin.ModelAdmin): list_display = ('title', 'author_name') list_select_related = ('author',) def author_name(self, obj): return obj.author.name
class BookAdmin(admin.ModelAdmin): list_display = ('title', 'author_name') def author_name(self, obj): return obj.author.name
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using list_select_related to fetch related data | Minimal extra DOM nodes | Single reflow | Low paint cost | [OK] Good |
| Querying related data per row without optimization | More DOM nodes due to delayed data | Multiple reflows | Higher paint cost | [X] Bad |
| Displaying many fields in list_display | Large DOM tree | Multiple reflows | High paint cost | [X] Bad |
| Limiting fields in list_display | Smaller DOM tree | Single reflow | Low paint cost | [OK] Good |