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, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기