
Django Admin
ModelAdmin, list_display, list_filter, search_fields, inlines, custom actions, admin customization
1What is the main role of the ModelAdmin class in Django?
What is the main role of the ModelAdmin class in Django?
답변
ModelAdmin is the class that represents a model in the Django admin interface. It allows customizing how a model is displayed and behaves in the admin, including which columns are shown, available filters, and possible actions. To use it, create a ModelAdmin subclass and register it with the corresponding model.
2How to register a model with its custom ModelAdmin class in Django?
How to register a model with its custom ModelAdmin class in Django?
답변
To register a model with a custom ModelAdmin class, use admin.site.register() passing the model and ModelAdmin class as arguments. An alternative is using the @admin.register(Model) decorator on the ModelAdmin class. Registration is typically done in the app's admin.py file.
3What is the purpose of the list_display attribute in a ModelAdmin class?
What is the purpose of the list_display attribute in a ModelAdmin class?
답변
The list_display attribute specifies which columns to show in the admin object list view. It accepts a tuple or list of model field names, callables, or ModelAdmin methods. By default, only the model's __str__ representation is shown. list_display greatly improves the readability and usability of the admin interface.
How to add a custom calculated column in list_display?
What is the role of the list_filter attribute in ModelAdmin?
+17 면접 질문