Issue
I created customized usercreationform
class RegisterForm(UserCreationForm):
class Meta:
model = Users #personal User model
fields = (
"username",
"first_name",
"last_name",
"email",
"adresse",
"phonenumber",
)
The simple question is if it works without "password1", "password2" in fields?
class RegisterForm(UserCreationForm):
class Meta:
model = Users #personal User model
fields = (
"username",
"first_name",
"last_name",
"email",
"adresse",
"phonenumber",
"password1",
"password2",
)
if both this code and code above work, what makes difference between the two codes?
Solution
In your case you define in Meta :
Model = Users #your own model
So, the two options will work if you have these fields in your own model. Because in Meta, fields will point your model, not Django User model.
Nevertheless, in your model you must not have 2 fields "password". Only one. In UserCreationForm
Class Meta:
Model = User
And the UserCreationForm adds two fields "password1" and "password2" for a special clean method. If password1==password2 then it will save a hash of the password in User.password.
You should never save a plain text password in your database for security reasons.
UserCreationForm is a easy way to create user (with a unique username). If you want to add some attributes Django recommands to make your own model (named Person for example) with a foreign Key to django.contrib.auth.User and all the other fields you want to add to the user in your own model.
I Hope I answered to your question.
Answered By - cd187
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.