Why would it make sense to switch from different form type? I use below form to get information that I like to save to user database? Part of information I need ot update goes to Additional user info class, I would like to stay in my own form.
-Thanks maanantai 19. tammikuuta 2015 11.26.47 UTC+2 Daniel Roseman kirjoitti: > > On Monday, 19 January 2015 09:22:02 UTC, joulumaa wrote: >> >> I have created user earlier in code with email address and password. >> Created users work fine. >> Now in later phase I asked more information and would like to fill in >> first_name and last_name. >> Code shows old first_name and last_name properly if set in admin view, >> but logged in user cannot save his information for some reason? >> >> p=User.objects.get(username=request.user.username) >> if request.method == 'POST': >> form = AdditionalCandidateInfo(request.POST) >> if form.is_valid(): >> p.first_name=form.cleaned_data['first_name'] >> p.last_name=form.cleaned_data['last_name'] >> p.save() >> return HttpResponseRedirect('/') >> else: >> form = >> AdditionalCandidateInfo(initial={'first_name':p.first_name,'last_name':p.last_name}) >> >> >> -thanks for help >> > > You should be using a ModelForm, and pass the `instance` argument when > instantiating the form. > > Also there's no point querying User: `request.user` is *already* the > relevant User instance. > -- > DR. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/22331ffc-41b6-4005-8487-acc62a761750%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.