Complete the code to filter books with a title containing 'django'.
books = Book.objects.filter(title__[1]='django')
The icontains lookup filters case-insensitively for the substring 'django' in the title.
Complete the code to order books by their publication date descending.
books = Book.objects.order_by('[1]')
Prefixing the field name with a minus sign - orders descending.
Fix the error in the code to search books by author name case-insensitively.
books = Book.objects.filter(author__[1]='john doe')
icontains allows case-insensitive substring matching, suitable for searching names.
Fill both blanks to filter books published after 2020 and order by title ascending.
books = Book.objects.filter(publication_year__[1]=2020).order_by('[2]')
gt means greater than, so books after 2020 are filtered. Ordering by title sorts ascending.
Fill all three blanks to create a dictionary of book titles and authors for books with rating above 4, ordered by rating descending.
result = {book.[1]: book.[2] for book in Book.objects.filter(rating__[3]=4).order_by('-rating')}We use title as keys and author as values. The filter uses gt to get ratings above 4. Ordering by -rating sorts descending.