Answer the question
In order to leave comments, you need to log in
How to fix this (UserCreationForm, AbstractUser)?
I registered on the site in this way:
1) Expanded the user model by adding a field for the phone:
class User(AbstractUser):
phone = models.CharField(max_length=50)
AUTH_USER_MODEL='myapp.User'
manage.py makemigrations
manage.py migrate
class CreateForm(UserCreationForm):
error_messages = {
'duplicate_username': "Пользователь с таким именем уже существует",
'password_mismatch': "Введенные пароли не совпадают"
}
username = forms.RegexField(label="Имя пользователя:", max_length=30,
regex=r'^[\[email protected]+-]+$', widget=forms.TextInput(attrs={'class': 'form-control'}))
password1 = forms.CharField(label="Пароль:",
widget=forms.PasswordInput(attrs={'class': 'form-control'}))
password2 = forms.CharField(label="Повторите пароль:",
widget=forms.PasswordInput(attrs={'class': 'form-control'}))
def signup(request):
if request.method == 'POST':
form = CreateForm(request.POST)
if form.is_valid():
username = cleaned_data['username']
password = cleaned_data['password1']
User.objects.create_user(username=username, password=password)
return redirect('/success/')
elif request.method == 'GET':
form = CreateForm()
return render(request, 'core/signup.html', {'form': form})
Exception Type: ProgrammingError at /signup/
Exception Value: relation "auth_user" does not exist
LINE 1: SELECT (1) AS "a" FROM "auth_user" WHERE "auth_user"."userna...
^
from myapp.models import User
class Meta:
model = User
fields = ("username",)
Answer the question
In order to leave comments, you need to log in
The doc says:
Depends on the User model. Must be re-written for any custom user model.
Those. you need to rewrite the form. And that's not the only thing that needs to be rewritten. Actually, everything is painted in the dock.
If the task is only to store additional information about the user, then it is easier to make a separate UserProfile model and associate it with the main OneToOne.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question