I am using django-userena. I have a model called UserProfile. I’ve added extra fields in signup form. and These fields are show up correctly but data is not saved. I want to save some fields data into another Model (Business) too. For example I’ve two field like contact and business. I want contact field will goes to UserProfile Model and business field will goes to Business Model. any clue? Thank you
Here is my code
class SignupFormExtra(SignupForm):
address = forms.CharField(label=_(u'Address'),max_length=30,required=False)
contact = forms.CharField(label=_(u'Contact'),max_length=30,required=False)
business = forms.CharField(label=_(u'Business Name'),max_length=30,required=False)
def save(self):
"""
Override the save method to save the first and last name to the user
field.
"""
user_profile = super(SignupFormExtra, self).save(commit=False)
user_profile.address = self.cleaned_data['address']
user_profile.contact = self.cleaned_data['contact']
user_profile.business = self.cleaned_data['business']
user_profile.save()
return user_profile
UPDATE : I am storing those values on a User instance… I want toe storing them on Profile model — an instance that’s bound to the User
Author of Userena here. I already had an e-mail correspondence with “no_access”, but it’s worth pointing to the solution if others have the same problem. The first mistake was that the
savemethod returns a profile. This is not true, it returns a DjangoUser. Because of this you first have to fetch the profile and make the changes to it. Save the profile and then return the user again to keep it compatible with Userena.For the
Businessmodel, just add it in thesavemethod also.After creating the form, don’t forget to override the userena form in your urls.py. Something like this will do:
That should do the trick! Good luck.