Challenge - 5 Problems
Django Admin Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What is the effect of list_display in ModelAdmin?
Consider this Django admin customization:
What will the admin list page for Book show?
class BookAdmin(admin.ModelAdmin):
list_display = ('title', 'author', 'published_date')What will the admin list page for Book show?
Attempts:
2 left
💡 Hint
list_display controls which fields appear as columns in the admin list view.
✗ Incorrect
The list_display attribute in ModelAdmin specifies exactly which model fields appear as columns in the admin list page. Here, title, author, and published_date will be shown as columns.
📝 Syntax
intermediate1:30remaining
Which ModelAdmin code correctly adds a search box for 'name' field?
You want to add a search box in Django admin to search by the 'name' field of a model. Which code snippet is correct?
Attempts:
2 left
💡 Hint
search_fields must be a list or tuple of field names.
✗ Incorrect
The search_fields attribute must be a list or tuple of strings naming the fields to search. Option A uses a list correctly. Option A uses a wrong attribute name. Option A uses a string instead of list. Option A uses a string in parentheses, which is not a tuple.
🔧 Debug
advanced2:00remaining
Why does this ModelAdmin code cause an error?
Given this code:
What error will Django admin raise when loading this ModelAdmin?
class ProductAdmin(admin.ModelAdmin):
list_filter = 'category'
What error will Django admin raise when loading this ModelAdmin?
Attempts:
2 left
💡 Hint
list_filter must be a list or tuple of field names.
✗ Incorrect
list_filter expects an iterable like a list or tuple. Passing a string causes Django to treat it as an iterable of characters, which is invalid and raises a TypeError.
❓ state_output
advanced2:00remaining
What is the output of this ModelAdmin with custom method in list_display?
Consider this code:
What will the admin list page show in the 'Customer' column?
class OrderAdmin(admin.ModelAdmin):
list_display = ('id', 'customer_name')
def customer_name(self, obj):
return obj.customer.first_name + ' ' + obj.customer.last_name
customer_name.short_description = 'Customer'What will the admin list page show in the 'Customer' column?
Attempts:
2 left
💡 Hint
Custom methods in list_display can show computed values.
✗ Incorrect
Defining a method named customer_name and including it in list_display allows Django admin to call it for each object. The method returns the full name, so the column shows the combined first and last names.
🧠 Conceptual
expert2:30remaining
Which ModelAdmin feature allows grouping fields in the admin form?
You want to organize fields in the Django admin form into sections with titles. Which ModelAdmin attribute do you use?
Attempts:
2 left
💡 Hint
Think about grouping fields with headings in the form view.
✗ Incorrect
The fieldsets attribute lets you group fields into sections with titles in the admin form. list_display controls list columns, search_fields adds search box, and list_filter adds filters.