I extended standard user model with UserProfile model, with following fields:
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name='profile')
gender = models.CharField(max_length=30)
info = models.CharField(max_length=30)
but while creating a new user using this form:
class SignupForm(forms.Form):
first_name = forms.CharField(max_length=30, label='First name')
last_name = forms.CharField(max_length=30, label='Last name')
info = forms.CharField(max_length=30, label='info')
def save(self, user):
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
profile = UserProfile()
profile.user = user
profile.info = self.cleaned_data['info']
profile.save()
user.profile = profile
user.save()
the 'info' is always empty ('') in the database (as is any other field except id). Standard attributes (first, last name) are saved correctly.
I tried debugging and the error is not related to SQL, as the query is not right:
INSERT INTO "user_profile" ("user_id", "info") VALUES (17, '',
'') RETURNING "user_profile"."id";
But, when I debug the value of user.profile.info using pdb it works correctly:
(Pdb) user.profile.info
u'info passed from form'