[Answered ]-How do I make each individual a user from a model?

1👍

This is done at the model level as shown.

class TeacherData(models.Model):
    school = models.ForeignKey(School,on_delete=models.CASCADE)
    first_name = models.CharField(max_length=20)
    last_name = models.CharField(max_length=20)
    email = models.EmailField()

    def save(self, *args, **kwargs):
            self.user = User.objects.create_user(username=self.first_name,password=str(self.email),is_teacher = True,is_student = False,school_id=self.school.id)
            self.user.save()  # mandatory as create_user is not recognized as save operation
            super().save(*args, **kwargs)
👤Ptar

Leave a comment