I’ve set up my Django models for a school system. Now I need help figuring out how to get info about student registrations and teacher assignments. Here’s what I’ve got:
from django.db import models
class Instructor(models.Model):
name = models.CharField(max_length=100)
class Pupil(models.Model):
name = models.CharField(max_length=100)
id_number = models.IntegerField()
class Subject(models.Model):
title = models.CharField(max_length=100)
code = models.CharField(max_length=20)
class Enrollment(models.Model):
pupil = models.ForeignKey(Pupil, on_delete=models.CASCADE)
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
instructor = models.ForeignKey(Instructor, on_delete=models.CASCADE)
date_enrolled = models.DateTimeField(auto_now_add=True)
How can I query these models to find out which pupils are enrolled in which subjects, and which instructors are teaching them? Any help would be great!