1👍
Your OnetoOneField
is not implementation of User model.
https://docs.djangoproject.com/en/1.6/ref/models/fields/#ref-onetoone
You can access OneToOneField
as object.user
attribute in your case.
Since you are using inbuilt UserCreationForm
which implements set_password
, you can create a method in your model called set_password
and call self.user.set_password
But I recommend you look into custom user implementation:
https://docs.djangoproject.com/en/1.6/topics/auth/customizing/#auth-custom-user
EDIT:
This is just a concept according to what I got from your question:
class UserProfile(models.Model):
user = models.OneToOneField(User)
.....your other attributes
also for RegistrationForm you could do something like:
class MyRegistrationForm(UserCreationForm):
....your registration form attributes from UserProfile Model
class Meta:
fields = ('username', 'email', 'firstname', 'lastname') # fields of User Model not your UserProfile Model
def save(self, commit=True):
user = super(MyRegistrationForm, self).save(commit=commit)
userprofile = UserProfile(user=user)
userprofile.attribute = form.cleaned_data[attribute_name]...
return user|userprofile #as required
Also csrf
is already available in template as {% csrf_token %}
Source:stackexchange.com