Whats the problem with this code ?
models.py
class userprofile(models.Model):
user = models.OneToOneField(User)
Firstname = models.CharField(max_length=20)
Middlename = models.CharField(max_length=20)
Surname = models.CharField(max_length=20)
Gender = models.CharField(max_length=1, blank=False, choices=GENDER_CHOICES)
Date_of_Birth = models.DateField()
Hometown = models.ForeignKey(city)
StudentType = models.CharField(max_length=20, blank=False, choices=STUDENT_CHOICES)
forms.py
from django.contrib.auth
class RegForm(ModelForm):
Date_of_Birth = forms.DateField(widget=SelectDateWidget(years=[y for y in range(1960,2005)]))
class Meta:
model = userprofile
exclude = ('user',)
views.py
from django.contrib.auth.forms import UserCreationForm
def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
uprofile = RegForm(request.POST)
if form.is_valid() and uprofile.is_valid():
userid = form.save()
a = RegForm(request.POST,user = userid)
a.save()
return direct_to_template('success.html',{})
else:
userform = UserCreationForm()
RF = RegForm()
return render_to_response('register.html',{
'uf': userform,
'rf': RF,
})
return render_to_response('regcheck1.html',{})
regcheck1.html
<form method="POST" id="greatform" action="/cd/registration/register/">{% csrf_token %}
{{ rf.as_p }}
{{ uf.as_p }}
<p><input type="submit" value="go"/></p>
</form>
The user model is getting saved with username and password but the userprofile isn;t :(
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment