0
0
Djangoframework~10 mins

ModelForm for model-backed forms 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 ModelForm class from Django forms.

Django
from django.forms import [1]
Drag options to blanks, or click blank then click option'
AModelForm
BForm
CCharField
DModel
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'Form' instead of 'ModelForm'.
Trying to import from 'django.models' instead of 'django.forms'.
2fill in blank
medium

Complete the code to define a ModelForm class for the 'Book' model.

Django
class BookForm([1]):
    class Meta:
        model = Book
        fields = '__all__'
Drag options to blanks, or click blank then click option'
AModelForm
Bforms.Form
CForm
Dmodels.Model
Attempts:
3 left
💡 Hint
Common Mistakes
Inheriting from 'Form' instead of 'ModelForm'.
Using 'models.Model' as a base class for the form.
3fill in blank
hard

Fix the error in the Meta class to specify only the 'title' and 'author' fields.

Django
class Meta:
    model = Book
    fields = [1]
Drag options to blanks, or click blank then click option'
A'title, author'
B['title', 'author']
C'title author'
D('title author')
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single string with commas instead of a list.
Using a string without commas or brackets.
4fill in blank
hard

Fill both blanks to create a ModelForm for the 'Author' model including only 'name' and 'email' fields.

Django
class AuthorForm([1]):
    class Meta:
        model = [2]
        fields = ['name', 'email']
Drag options to blanks, or click blank then click option'
AModelForm
BForm
CAuthor
DBook
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Form' instead of 'ModelForm'.
Setting model to 'Book' instead of 'Author'.
5fill in blank
hard

Fill all three blanks to create a ModelForm for 'Publisher' model with only 'name' and 'address' fields and import the model.

Django
from .models import [1]

class PublisherForm([2]):
    class Meta:
        model = [3]
        fields = ['name', 'address']
Drag options to blanks, or click blank then click option'
APublisher
BModelForm
DAuthor
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong model.
Inheriting from 'Form' instead of 'ModelForm'.
Setting model to a different model than imported.