Complete the code to define a one-to-many relationship where each Book belongs to one Author.
class Book(models.Model): title = models.CharField(max_length=100) author = models.[1](Author, on_delete=models.CASCADE)
The ForeignKey field creates a one-to-many relationship where each Book is linked to one Author.
Complete the code to define a many-to-many relationship between Student and Course.
class Student(models.Model): name = models.CharField(max_length=50) courses = models.[1](Course)
The ManyToManyField allows each Student to enroll in multiple Courses and each Course to have many Students.
Fix the error in the code to correctly link Profile to User with a one-to-one relationship.
class Profile(models.Model): user = models.[1](User, on_delete=models.CASCADE)
OneToOneField is used to link Profile to User so each Profile belongs to exactly one User.
Fill both blanks to create a dictionary comprehension that maps each Author's name to the count of their books.
book_counts = {author.name: [1] for author in authors if [2] > 0}Use author.book_set.count() to count books related to each author. The same expression checks if the count is greater than zero.
Fill all three blanks to create a dictionary comprehension mapping each Course's title to the number of enrolled students for courses with more than 2 students.
course_students = {course.[1]: [2] for course in courses if course.students.[3] > 2}course.name instead of course.titlecount() on the related managerUse course.title for the course name, course.students.count() to count enrolled students, and count() to check if the number is greater than 2.