Complete the code to fetch all books with their related authors efficiently.
books = Book.objects.[1]('author')
Using select_related fetches related foreign key objects in one query, improving efficiency.
Complete the code to fetch all orders with their related customers using the best query optimization.
orders = Order.objects.[1]('customer')
select_related is best for single-valued relationships like foreign keys to fetch related objects in one query.
Fix the error in the code to optimize fetching books and their publishers in one query.
books = Book.objects.[1]('publisher')
select_related is used to follow foreign key relationships and fetch related objects in one query.
Fill both blanks to create a dictionary of authors and their books, optimizing queries.
author_books = {author.name: author.[1].all() for author in Author.objects.[2]('book_set')}Use prefetch_related to fetch reverse foreign key sets like book_set efficiently.
Fill all three blanks to create a dictionary of orders and their related customer names, optimizing queries.
order_dict = {order.id: order.[1].[2] for order in Order.objects.[3]('customer')}Use select_related to fetch the related customer object, then access its name attribute.