[Answer]-Convert Django ModelForm to use User object

1πŸ‘

βœ…

To answer your second question:

Use UserCreationForm to represent registration process for User class, it handles validation and saving for you and you can always extend it (i.e. to add email field)

User class has a lot of related forms, depending of the use case: authentication, registration, password change etc. read the docs on authentication to find more.

https://docs.djangoproject.com/en/1.5/topics/auth/default/#module-django.contrib.auth.forms

πŸ‘€mariodev

0πŸ‘

You can get the validated data from the form using cleaned_date:

username = form.cleaned_data['username']
email = form.cleaned_data['email']
password = form.cleaned_data['password']

newUser = User.objects.create_user(username, email, password)

Now I think your approach has serious problems since you are saving the form again after creating the user object, also the User object expects the password field to be a hash of the password and some meta data, etc.
I highly recommend you use django-registration (or at least have a look at it) which handles all this stuff for you in addition to email validation, all you need is to provide the templates(and also you can find some templates for it like this )

πŸ‘€almalki

Leave a comment