Recall & Review
beginner
What is the purpose of Django's CreateView?
CreateView is a class-based view in Django used to display a form for creating a new object and saving it to the database.
Click to reveal answer
beginner
Which attribute must you define in a CreateView to specify the model to create?
You must define the
model attribute to tell CreateView which database model to create an instance of.Click to reveal answer
beginner
How do you specify which fields appear in the form generated by CreateView?
Use the
fields attribute as a list or tuple of field names to include in the form.Click to reveal answer
intermediate
What method can you override in CreateView to customize what happens after a successful form submission?
Override the
get_success_url() method to define the URL to redirect to after the object is created.Click to reveal answer
beginner
True or False: CreateView automatically handles form validation and saving the new object.
True. CreateView manages form display, validation, and saving the new object to the database automatically.
Click to reveal answer
Which attribute in CreateView defines the database model to create?
✗ Incorrect
The 'model' attribute tells CreateView which model to create an instance of.
How do you specify which fields appear in the form of a CreateView?
✗ Incorrect
The 'fields' attribute lists the model fields to include in the form.
What method do you override to change the redirect URL after creating an object?
✗ Incorrect
Override 'get_success_url()' to specify where to redirect after successful creation.
True or False: CreateView requires you to manually save the form data to the database.
✗ Incorrect
CreateView automatically saves the form data when valid.
Which of these is NOT typically set in a CreateView?
✗ Incorrect
'queryset' is usually used in ListView or DetailView, not CreateView.
Explain how to create a simple Django CreateView to add new objects to a model.
Think about what you need to tell Django about the model and form fields.
You got /5 concepts.
Describe what happens behind the scenes when a user submits a form in a CreateView.
Consider the flow from form submission to response.
You got /4 concepts.