Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserProfile(models.Model):
- user = models.ForeignKey(User, unique=True, related_name="connect")
- location = models.CharField(max_length=20, blank=True, null=True)
- #UserCreationForm for User Model
- class UserProfileForm(ModelForm):
- class Meta:
- model = UserProfile
- exclude = ("user", )
- def register(request):
- if request.method == 'POST':
- form1 = UserCreationForm(request.POST)
- form2 = UserProfileForm(request.POST)
- if form1.is_valid():
- #create initial entry for User object
- username = form1.cleaned_data["username"]
- password = form1.cleaned_data["password"]
- new_user = User.objects.create_user(username, password)
- # What to do here to save "location" field in a UserProfile
- # object that corresponds with the new_user User object that
- # we just created in the previous lines
- else:
- form1 = UserCreationForm()
- form2 = UserProfileForm()
- c = {
- 'form1':UserCreationForm,
- 'form2':form2,
- }
- c.update(csrf(request))
- return render_to_response("registration/register.html", c)
- def register(request):
- if request.method == 'POST':
- form1 = UserCreationForm(request.POST)
- form2 = UserProfileForm(request.POST)
- if form1.is_valid() and form2.is_valid():
- #create initial entry for User object
- user = form1.save()
- userprofile = form2.save(commit=False)
- userprofile.user = user
- userprofile.location = get_the_location_somehow()
- userprofile.save()
- # What to do here to save "location" field in a UserProfile
- # object that corresponds with the new_user User object that
- # we just created in the previous lines
- else:
- form1 = UserCreationForm()
- form2 = UserProfileForm()
- c = {
- 'form1':UserCreationForm,
- 'form2':form2,
- }
- c.update(csrf(request))
- return render_to_response("registration/register.html", c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement