0
0
Djangoframework~10 mins

UpdateView for editing 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 generic UpdateView class from Django.

Django
from django.views.generic import [1]
Drag options to blanks, or click blank then click option'
AUpdateView
BListView
CCreateView
DDeleteView
Attempts:
3 left
💡 Hint
Common Mistakes
Importing ListView instead of UpdateView
Importing CreateView which is for creating new objects
2fill in blank
medium

Complete the code to specify the model to edit in the UpdateView subclass.

Django
class BookUpdateView(UpdateView):
    model = [1]
Drag options to blanks, or click blank then click option'
AReview
BBook
CPublisher
DAuthor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different model name than the one intended for editing
Forgetting to set the model attribute
3fill in blank
hard

Fix the error in the UpdateView by completing the code to specify the fields to edit.

Django
class BookUpdateView(UpdateView):
    model = Book
    fields = [1]
Drag options to blanks, or click blank then click option'
A['title', 'author']
Btitle, author
Ctitle author
Dtitle; author
Attempts:
3 left
💡 Hint
Common Mistakes
Listing fields as a comma-separated string without brackets
Using spaces or semicolons instead of a list
4fill in blank
hard

Fill both blanks to complete the URL pattern for the UpdateView with a primary key parameter.

Django
path('book/<[1]:pk>/edit/', BookUpdateView.as_view(), name='book_edit')
Drag options to blanks, or click blank then click option'
Auuid
Bstr
Cslug
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'str' or 'slug' which expect different formats
Omitting the converter type
5fill in blank
hard

Fill all three blanks to complete the UpdateView with success URL and template name.

Django
class BookUpdateView(UpdateView):
    model = Book
    fields = ['title', 'author']
    template_name = [1]
    success_url = reverse_lazy([2])

# In urls.py
path('book/<int:pk>/edit/', [3].as_view(), name='book_edit')
Drag options to blanks, or click blank then click option'
A'books/book_form.html'
B'books:book_list'
CBookUpdateView
D'book_edit.html'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect template paths
Wrong named URL in success_url
Not referencing the correct view class in urls.py