Complete the code to get all books written by an author with id 1.
books = Book.objects.filter(author__[1]=1)
The double underscore syntax lets you filter by fields of related models. Here, author__id=1 filters books whose author's id is 1.
Complete the code to get all authors who have written a book titled 'Django Basics'.
authors = Author.objects.filter(book__[1]='Django Basics')
We filter authors by the title of their related books using book__title='Django Basics'.
Fix the error in the code to get all books with at least one review rating greater than 4.
books = Book.objects.filter(review__[1]__gt=4)
The related Review model has a field named 'rating'. Using review__rating__gt=4 filters books with reviews rated above 4.
Fill both blanks to get all authors who have written more than 3 books.
authors = Author.objects.annotate(book_count=[1]).filter(book_count__[2]=3)
We use annotate with Count('book') to count books per author, then filter authors with book_count greater than 3 using book_count__gt=3.
Fill all three blanks to get all books with reviews rated at least 4 and order them by author's name.
books = Book.objects.filter(review__[1]__[2]=4).order_by('[3]')
Filter books with reviews having rating greater or equal to 4 using review__rating__gte=4. Then order by author's name with order_by('author__name').