I want to create 2 custom user models(profiles) which will have a field with OneToOne mapping to the default Django auth User model.
class StudentProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
# several fields here
class TeacherProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
# more fields here
I am able to implement it using signals if it was a single User Profile model. I have 2 forms and 2 views, one for each registration.
How do I make only an object of the Profile model to be created when its respective form function is executed?
My views.py file
def student_register(request):
if request.method == "POST":
form = StudentRegisterForm(request.POST)
if form.is_valid():
form.save()
return redirect('student-login')
else:
form = StudentRegisterForm()
context = {'form': form}
return render(request, 'users/student_register.html', context)