python - How to combine 2 forms for use on the same page? -
i have userprofile model add together metadata around standard django user model. creating registration page, , want user input both basic user info captured in user model general profile info captured in userprofile model.
how can capture , validate both of these models in 1 request in django, presumably through forms?
there valid debate whether maintain user , userprofile separated. if want utilize separate classes:
@csrf_protect def register(request, extra_context=none): if request.method == 'post': user_form = adduserform(data=request.post, files=request.files) user_profile_form = adduserprofileform(data=request.post, files=request.files) if user_form.is_valid() , user_profile_form.is_valid(): new_user = user_form.save(request.get_host()) new_user_profile = user_profile_form.save(request.get_host(), new_user) homecoming httpresponseredirect(reverse('registration_complete')) else: user_form = adduserform() user_profile_form = adduserprofileform() context = {} homecoming render_to_response('registration_form.html', { 'user_form': user_form, 'user_profile_form': user_profile_form }, context_instance=context) python django
No comments:
Post a Comment