Django version: 4.0.2 Django-Registration version: 0.8 App name: userAccounts
PROBLEM: Im trying to create a user type called professor extending the user model. I can complete the registration process, the problem is that only the user is saved on the DB, the professor table keep empty. So i think the problem could be in the save method. Some clue about what could be the problem?
SETTINGS.PY
AUTH_PROFILE_MODULE = "userAccounts.Professor"
MODELS.PY - Here i create the model that extending from user and a example field
from django.db import models
from django.contrib.auth.models import User
class Professor(models.Model):
user = models.ForeignKey(User, unique=True)
exampleField = models.CharField(max_length=100)
FORMS.PY - When a user is saved, i save a new_profile in the professor table.
from django import forms
from registration.forms import RegistrationForm
from models import Professor
from registration.models import RegistrationProfile
class CustomRegistrationForm(RegistrationForm):
exampleField = forms.CharField()
def save(self, profile_callback=None):
new_user = RegistrationProfile.objects.create_inactive_user(
username=self.cleaned_data['username'],
password=self.cleaned_data['password1'],
email = self.cleaned_data['email'])
new_professor = Professor(
user=new_user,
exampleField=self.cleaned_data['exampleField'])
new_professor.save()
return new_user
NOTE: Im following this post: Registration form with profile's field