0
0
Djangoframework~10 mins

Search and ordering 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 filter books with a title containing 'django'.

Django
books = Book.objects.filter(title__[1]='django')
Drag options to blanks, or click blank then click option'
Aicontains
Bcontains
Cstartswith
Dexact
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' which is case-sensitive and may miss matches.
Using 'exact' which looks for an exact match, not substring.
2fill in blank
medium

Complete the code to order books by their publication date descending.

Django
books = Book.objects.order_by('[1]')
Drag options to blanks, or click blank then click option'
A-date_published
B-publication_date
Cdate_published
Dpublication_date
Attempts:
3 left
💡 Hint
Common Mistakes
Ordering ascending by missing the minus sign.
Using a wrong field name that does not exist.
3fill in blank
hard

Fix the error in the code to search books by author name case-insensitively.

Django
books = Book.objects.filter(author__[1]='john doe')
Drag options to blanks, or click blank then click option'
Acontains
Bstartswith
Ciexact
Dicontains
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' which is case-sensitive.
Using 'iexact' which requires full exact match.
4fill in blank
hard

Fill both blanks to filter books published after 2020 and order by title ascending.

Django
books = Book.objects.filter(publication_year__[1]=2020).order_by('[2]')
Drag options to blanks, or click blank then click option'
Agt
Blt
Ctitle
D-title
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lt' which filters before 2020.
Ordering by '-title' which sorts descending.
5fill in blank
hard

Fill all three blanks to create a dictionary of book titles and authors for books with rating above 4, ordered by rating descending.

Django
result = {book.[1]: book.[2] for book in Book.objects.filter(rating__[3]=4).order_by('-rating')}
Drag options to blanks, or click blank then click option'
Atitle
Bauthor
Cgt
Drating
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rating' or 'author' as dictionary keys incorrectly.
Using 'lt' or 'gte' instead of 'gt' for filtering.