Complete the code to calculate the total number of books in the database using Django's ORM.
from django.db.models import [1] total_books = Book.objects.aggregate({"total": [1]('id')})
The Count function counts the number of records. Here, it counts all book IDs.
Complete the code to annotate each author with the number of books they have written.
from django.db.models import [1] authors = Author.objects.annotate(book_count=[1]('book'))
The Count function counts related books per author.
Fix the error in the code to get the average price of all books.
from django.db.models import [1] avg_price = Book.objects.aggregate(avg_price=[1]('price'))
The Avg function calculates the average value of the specified field.
Fill both blanks to annotate each book with the total number of pages and filter books with more than 300 pages.
from django.db.models import [1] books = Book.objects.annotate(total_pages=[1]('pages')).filter(total_pages__[2]=300)
Sum adds up the pages, and gt means 'greater than' to filter books with more than 300 pages.
Fill all three blanks to annotate authors with the maximum book price, minimum book price, and average book price.
from django.db.models import [1], [2], [3] authors = Author.objects.annotate(max_price=[1]('book__price'), min_price=[2]('book__price'), avg_price=[3]('book__price'))
Max, Min, and Avg calculate the highest, lowest, and average book prices respectively.