Save to User table first_name and last_name from a page with a different form

11 views
Skip to first unread message

Brad Rice

unread,
Jan 22, 2014, 9:48:27 AM1/22/14
to django...@googlegroups.com
I have a registration and login page that only takes username and password. After they register or login, they are taken to a profile form where they can provide additional information such as address and phone numbers. I'm using a Model Form CreateView there. On that page I want the First Name and Last Name fields to  save to the auth_user table rather than that Profile Form model. How do I have two fields submit data to the auth_user table and the other fields submit to the Profile table?

Brad Rice

unread,
Jan 22, 2014, 4:22:06 PM1/22/14
to django...@googlegroups.com
I think I figured it out. The user is on the reuqest so it was pretty easy.

def form_valid(self, form):
        obj = form.save(commit=False)
        obj.created_by = self.request.user
        obj.application_id = self.kwargs['app_id']
        u = self.request.user
        u.last_name = obj.last_name;
        u.first_name = obj.first_name;
        obj.save()
        u.save()
        #reverse_lazy = lambda name=answers, *args : lazy(reverse, str)(name, args=args)
        return HttpResponseRedirect(reverse('requestform:answers', kwargs={'app_id': obj.application_id}))
Reply all
Reply to author
Forward
0 new messages