Django

Django Admin

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

20 câu hỏi phỏng vấn·
Mid-Level
1

What is the main role of the ModelAdmin class in Django?

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững Django cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí