I dont know why the margins are squashing everything, ill try and post my code again this time without the comments
if request.method == 'POST': form = UserCreationForm(request.POST) extraform = CustomProfileForm(request.POST) if form.is_valid(): userformInstance = form.save() extraformedit = extraform.save(commit=False) extraformedit.user = userformInstance extraformedit.save() return HttpResponseRedirect("/") Hope that works a bit better. On 4 Dec, 16:57, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Thanks for your help Brian, Im still quite confused. I think what Im > really not sure about is how to set the foreignkey manually as it > doesnt really talk about that in the documentation. > > Here is what I have now, if extraformedit.user is a foreignkey, how do > i connect it to the form I just saved?- > > if request.method == 'POST': > form = UserCreationForm(request.POST) > extraform = CustomProfileForm(request.POST) > if form.is_valid(): > userformInstance = form.save > () #save the form with the user data > and create an instance i can hook my profile to > extraformedit = extraform.save(commit=False) > #save the profile form with commit=false so i can modify it > extraformedit.user = userformInstance > #!!i think this is where im going wrong? assigning the user the > profile is attached to > extraformedit.save > () #save the edited > form to the database. > return HttpResponseRedirect("/") > > Am I way off? Again I am very new to this so sorry if this is a stupid > question. > > Phil > > On 3 Dec, 18:52, Brian Neal <[EMAIL PROTECTED]> wrote: > > > On Dec 3, 12:22 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > > wrote: > > > > ... > > > And here is my view for my signup page - > > > > def signup(request): > > > if request.method == 'POST': > > > form = UserCreationForm(request.POST) > > > extraform = CustomProfileForm(request.POST) > > > if form.is_valid(): > > > form.save() > > > extraform.save() > > > return HttpResponseRedirect("/") > > > else: > > > form = UserCreationForm() > > > extraform = CustomProfileForm() > > > > return render_to_response('signup.html', { > > > 'form': form, > > > 'extraform': extraform > > > }) > > > > This view doesnt work because it is not saving 'user' in > > > CustomProfileForm. > > > > Ok now the problem I am having is with the foreignkey in the custom > > > profile model, and successfully linking that to the User. > > > Yes. You need to set the user foreign key inside the extraform before > > you save it. See the discussion here about ModelForms save() with > > commit=False: > > >http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-sav... --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---