0
0
Djangoframework~10 mins

Why admin interface matters in Django - Test Your Understanding

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 the Django admin site.

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

admin.site.[1](Product)
Drag options to blanks, or click blank then click option'
Ainstall
Badd
Cinclude
Dregister
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add' or 'include' instead of 'register' causes errors.
Forgetting to import the model before registering.
2fill in blank
medium

Complete the code to customize the admin list display for a model.

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

@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
    list_display = ([1])
Drag options to blanks, or click blank then click option'
A'title', 'author'
Btitle, author
C['title', 'author']
D{'title', 'author'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or set instead of a tuple.
Forgetting quotes around field names.
3fill in blank
hard

Fix the error in the admin class to enable search functionality.

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

@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
    search_fields = [1]
Drag options to blanks, or click blank then click option'
A{'name', 'email'}
B['name', 'email']
C'name', 'email'
Dname, email
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string without brackets causes errors.
Using a set instead of a list or tuple.
4fill in blank
hard

Fill both blanks to add filters and ordering in the admin interface.

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

@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
    list_filter = [1]
    ordering = [2]
Drag options to blanks, or click blank then click option'
A('status', 'date')
B['status', 'date']
C('date',)
D['date']
Attempts:
3 left
💡 Hint
Common Mistakes
Using lists where tuples are expected or vice versa.
Forgetting the comma in single-item tuples.
5fill in blank
hard

Fill all three blanks to customize the admin form with readonly fields and fieldsets.

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

@admin.register(Profile)
class ProfileAdmin(admin.ModelAdmin):
    readonly_fields = [1]
    fieldsets = (
        (None, {'fields': [2]),
        ('Advanced options', {'classes': ('collapse',), 'fields': [3]),
    )
Drag options to blanks, or click blank then click option'
A('user',)
B('bio', 'location')
C('created_at', 'updated_at')
D['user']
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing lists and tuples inconsistently.
Forgetting to wrap field names in a list or tuple inside fieldsets.