0
0
Djangoframework~10 mins

Admin customization with ModelAdmin in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to register a model with a custom admin class.

Django
from django.contrib import admin
from .models import Book

class BookAdmin(admin.ModelAdmin):
    pass

admin.site.[1](Book, BookAdmin)
Drag options to blanks, or click blank then click option'
Ainstall
Badd
Cregister
Dinclude
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add' or 'include' instead of 'register'.
Forgetting to pass both model and admin class.
2fill in blank
medium

Complete the code to display the 'title' and 'author' fields in the admin list view.

Django
class BookAdmin(admin.ModelAdmin):
    list_display = ([1])
Drag options to blanks, or click blank then click option'
Atitle, author
B'title', 'author'
C['title', 'author']
D('title')
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around field names.
Using a list instead of a tuple.
3fill in blank
hard

Fix the error in the code to enable search by 'title' in the admin.

Django
class BookAdmin(admin.ModelAdmin):
    search_fields = [1]
Drag options to blanks, or click blank then click option'
A['title']
Btitle
C'title'
D('title')
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single string without list or tuple.
Using parentheses without comma, which is a string, not a tuple.
4fill in blank
hard

Fill both blanks to filter the admin list by 'published_date' and order by 'title'.

Django
class BookAdmin(admin.ModelAdmin):
    list_filter = ([1],)
    ordering = ([2],)
Drag options to blanks, or click blank then click option'
A'published_date'
B'title'
C'author'
D'created_at'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong field names for filtering or ordering.
Not using tuples (missing commas).
5fill in blank
hard

Fill all three blanks to customize the admin: show 'title' and 'author', enable search on 'title', and filter by 'status'.

Django
class BookAdmin(admin.ModelAdmin):
    list_display = ([1], [2])
    search_fields = [[3]]
    list_filter = ('status',)
Drag options to blanks, or click blank then click option'
A'title'
B'author'
D'published_date'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong types for search_fields.
Mixing up field names in list_display.