Django

Django Admin

ModelAdmin, list_display, list_filter, search_fields, inlines, custom actions, admin customization

20 面接問題·
Mid-Level
1

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.

2

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.

3

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.

4

How to add a custom calculated column in list_display?

5

What is the role of the list_filter attribute in ModelAdmin?

+17 面接問題

次の面接に向けてDjangoをマスター

すべての問題、flashcards、技術テスト、コードレビュー演習、面接シミュレーターにアクセス。

無料で始める