How to modify a models to be able to give access to users in django

I am working on a classroom project and I am completely new to Django. How to modify my models (course,user) so that I can add students to the course in two ways 1)By entering the class code by students. 2)By sending join invitations to students from a list of all students by selecting some by the teacher and if the student confirms/accepts he will be added.

i am attaching the models below

user model

class CustomUser(AbstractUser):
    email = models.EmailField()
    is_teacher = models.BooleanField(default=False)
    is_student = models.BooleanField(default=False)

Course Model

class Course(models.Model):
    course_name = models.CharField(max_length=200)
    course_id = models.CharField(max_length=10)
    course_sec = models.IntegerField(validators=[MinValueValidator(1),MaxValueValidator(25)])
    classroom_id = models.CharField(max_length=50,unique=True)
    created_by = models.ForeignKey(User,on_delete=models.CASCADE)
    slug=models.SlugField(null=True, blank=True)


    def __str__(self):
        return self.course_name

    def save(self, *args, **kwargs):
        self.slug = slugify(self.classroom_id)
        super().save(*args, **kwargs)

    def is_valid(self):
        pass
Back to Top