django - Problems Saving Data to Database -
this views.py
def signup(request): print "signup" if request.method == 'post': print "post signup" form = registerform(request.post) try: if form.is_valid(): print form.cleaned_data u = user.objects.create_user(form.cleaned_data['emailid'], form.cleaned_data['emailid'], form.cleaned_data['passwd1'] ) ui = userinfo() ui.user = u ui.class_of = form.cleaned_data['gradyear'] ui.grade = form.cleaned_data['grade'] ui.balance = 0 ui.save()
and in forms.py have:
class registerform(forms.form): grade_choices = ( (9,'9'), (10,'10'), (11,'11'), (12,'12') , ) curr_year = date.today().year grad_year_choices = ( (curr_year,curr_year), (curr_year+1,curr_year+1), (curr_year+2,curr_year+2), (curr_year+3,curr_year+3) , ) first_name = forms.charfield(max_length = 25) last_name = forms.charfield( max_length = 25) emailid = forms.emailfield() passwd1 = forms.charfield(max_length=100,widget=forms.passwordinput) passwd2 = forms.charfield(max_length=100,widget=forms.passwordinput) gradyear = forms.choicefield( choices=grad_year_choices) grade = forms.choicefield( choices=grade_choices) def clean(self): cleaned_data = super(registerform, self).clean() if cleaned_data['passwd1'] != cleaned_data['passwd2']: raise forms.validationerror({'passwd1':['password not match']}) if user.objects.filter(email=cleaned_data['emailid']).count(): raise forms.validationerror({'emailid':['email taken ']}) return cleaned_data
why print database except first_name , last_name??? (username, email, grade, gradyear, , password save)
edit: userinfo
class userinfo(models.model): user = models.onetoonefield(user, related_name='user_infos') class_of = models.integerfield() #username = user.username #fname = user.fname #lname = user.last_name #email = user.email #staff = user.is_staff pub_date = models.datetimefield( auto_now=true) grade = models.integerfield() balance = models.decimalfield(max_digits=6, decimal_places=2) #first_name = models.charfield(max_length = 25)
in code provided, never save first_name
, last_name
user
or userinfo
.
in def signup(request):
, right after line:
u = user.objects.create_user(form.cleaned_data['emailid'], form.cleaned_data['emailid'], form.cleaned_data['passwd1'] )
try including this:
u.first_name = form.cleaned_data['first_name'] u.last_name = form.cleaned_data['last_name'] u.save()
Comments
Post a Comment