Django how to create user with advanced model?

Good evening! The question itself in the header.
Made a model for Hyde:

And here is the question. I'm just learning django more.
Searched through the entire Internet.
I was able to make entrance through registration redux
and now.

Please show the code desirable, as I register users?
I.e. with the usual registration form. And yet, do not want the activation email on the email flew. It is possible to remove?

Thank you very much
July 12th 19 at 17:11
2 answers
July 12th 19 at 17:13
class UserRegistrationForm(forms.ModelForm):
 password = forms.CharField(label='Password', widget=forms.PasswordInput)
 password2 = forms.CharField(label='Repeat password', widget=forms.PasswordInput)

 class Meta:
 model = User
 fields = ('username', 'first_name', 'email')

 def clean_password2(self):
 cd = self.cleaned_data
 if cd['password'] != cd['password2']:
 raise forms.ValidationError('Passwords don\'t match.')
 return cd['password2']

def register(request):
 if request.method == 'POST':
 user_form = UserRegistrationForm(request.POST)

 if user_form.is_valid():
 # Create a new user object but avoid saving it yet
 new_user =
 # Set the chosen password
 # Save the User object
 return render(request,
 {'new_user': new_user})
 user_form = UserRegistrationForm()
 return render(request, 'template.html', {'user_form': user_form})
Thank you! Not working, but here I will deal with the problems)) - Dixie.Schuster commented on July 12th 19 at 17:16
Have already figured out. Everything works as it should! Thank you very much! Understand how to use them - Dixie.Schuster commented on July 12th 19 at 17:19
July 12th 19 at 17:15
Here is my code, if anyone is interested
class UserCreationForm(forms.ModelForm):
 password1 = forms.CharField(
 'style':'margin:10px; padding:10px;height:40px',
 'class':'form-control col-sm-8',
 'placeholder': 'Password please'
 password2 = forms.CharField(
 label='double passwd',
 'style':'margin:10px; padding:10px;height:40px',
 'class':'form-control col-sm-8',
 'placeholder': 'Double' password please'

 def clean_password2(self):
 password1 = self.cleaned_data.get('password1')
 password2 = self.cleaned_data.get('password2')
 if password1 and password2 and password1 != password2:
 raise forms.ValidationError('Passwd passwd and double error')
 return password2

 def save(self, commit=True):
 user = super(UserCreationForm, self).save(commit=False)
 user.set_password(self.cleaned_data['password1']) # the important thing here is to pass password1 or 2. But no password as in the example above
 if commit:
 return user

 class Meta:
 model = get_user_model()
 fields = ('email', 'lastname', 'firstname')
 widgets = {
 'email': forms.TextInput(attrs={
 'style':'margin:10px; padding:10px;height:40px',
 'class':'form-control col-sm-8',
 'placeholder': 'E-mail please'
 'lastname': forms.TextInput(attrs={
 'style':'margin:10px; padding:10px;height:40px',
 'class':'form-control col-sm-8',
 'placeholder': 'Lastname please'
 'firstname': forms.TextInput(attrs={
 'style':'margin:10px; padding:10px;height:40px',
 'class':'form-control col-sm-8',
 'placeholder': 'Firstname please'

Here is the view:
def registerPost(request):
 if request.method == "POST":
 user_form = UserCreationForm(request.POST)

 if user_form.is_valid():
 new_user =
 new_user.avatar = "fotos/no_image_dummy.png"
 return HttpResponseRedirect("/login")
 user_form = UserCreationForm()
 return render(request, 'register.html', {'form':user_form})

Find more questions by tags OOPDjangoPython