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
Source:stackexchange.com