0
0
Djangoframework~10 mins

ListView for displaying collections 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 ListView class from Django.

Django
from django.views.generic import [1]
Drag options to blanks, or click blank then click option'
AListView
BTemplateView
CFormView
DDetailView
Attempts:
3 left
💡 Hint
Common Mistakes
Importing DetailView instead of ListView
Forgetting to import from django.views.generic
2fill in blank
medium

Complete the code to define a ListView for the model named 'Book'.

Django
class BookListView([1]):
    model = Book
Drag options to blanks, or click blank then click option'
AUpdateView
BDetailView
CCreateView
DListView
Attempts:
3 left
💡 Hint
Common Mistakes
Using DetailView which shows one object
Using CreateView or UpdateView which are for forms
3fill in blank
hard

Fix the error in the ListView by completing the code to specify the template name.

Django
class AuthorListView(ListView):
    model = Author
    template_name = '[1]'
Drag options to blanks, or click blank then click option'
Aauthor_list.html
Blist_author.html
Cauthorlist.html
Dauthors.html
Attempts:
3 left
💡 Hint
Common Mistakes
Using a template name without underscore
Using plural form incorrectly
4fill in blank
hard

Fill both blanks to filter the queryset to only active items and order them by name.

Django
class ProductListView(ListView):
    model = Product
    queryset = Product.objects.filter([1]).order_by('[2]')
Drag options to blanks, or click blank then click option'
Ais_active=True
Bname
C-name
Dactive=True
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'active=True' instead of 'is_active=True'
Ordering by '-name' which reverses order
5fill in blank
hard

Fill all three blanks to customize the context object name and paginate the list by 10 items.

Django
class EventListView(ListView):
    model = Event
    context_object_name = '[1]'
    paginate_by = [2]
    template_name = '[3]'
Drag options to blanks, or click blank then click option'
Aevents
B10
Cevent_list.html
Devent
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular context name for a list
Setting paginate_by to a string instead of an integer
Incorrect template name format