0
0
Djangoframework~10 mins

Inline models for related data 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 import the inline admin class.

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

class ChapterInline([1]):
    model = Chapter
Drag options to blanks, or click blank then click option'
Aadmin.StackedInline
Badmin.ModelAdmin
Cadmin.TabularInline
Dadmin.InlineModelAdmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using ModelAdmin instead of an inline class.
Confusing TabularInline with StackedInline.
2fill in blank
medium

Complete the code to register the Book model with the Chapter inline.

Django
class BookAdmin(admin.ModelAdmin):
    inlines = [[1]]

admin.site.register(Book, BookAdmin)
Drag options to blanks, or click blank then click option'
AChapterInline[]
BChapterInline()
C[ChapterInline]
DChapterInline
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses to create an instance.
Not wrapping the inline class in a list.
3fill in blank
hard

Fix the error in the inline admin by completing the missing attribute.

Django
class ChapterInline(admin.StackedInline):
    model = Chapter
    extra = [1]
Drag options to blanks, or click blank then click option'
A2
B'2'
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number.
Using boolean values instead of an integer.
4fill in blank
hard

Fill both blanks to customize the inline admin to show 3 extra forms and use a tabular layout.

Django
class ChapterInline(admin.[1]):
    model = Chapter
    extra = [2]
Drag options to blanks, or click blank then click option'
ATabularInline
BStackedInline
C3
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing StackedInline with tabular layout.
Setting extra to 1 instead of 3.
5fill in blank
hard

Fill all three blanks to create an inline admin for a related model Author with 2 extra stacked forms and register it with the Book model.

Django
class [1](admin.[2]):
    model = Author
    extra = [3]

class BookAdmin(admin.ModelAdmin):
    inlines = [AuthorInline]

admin.site.register(Book, BookAdmin)
Drag options to blanks, or click blank then click option'
AAuthorInline
BStackedInline
C2
DTabularInline
Attempts:
3 left
💡 Hint
Common Mistakes
Using TabularInline instead of StackedInline.
Forgetting to name the class properly.
Setting extra to wrong number.