Last active
May 8, 2018 00:59
-
-
Save walison17/8e5cbc5b47aa2420e4a80e2a45fbaf8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import transaction | |
from django.contrib.auth.decorators import login_required | |
@login_required | |
@transaction.atomic | |
def profile(request): | |
if request.method == 'POST': | |
user_form = UserForm(request.POST, instance=request.user) | |
profile_form = ProfileForm(request.POST, instance=request.user.profile) | |
if user_form.is_valid() and profile_form.is_valid(): | |
user_form.save() | |
profile_form.save() | |
return redirect('/profile/') | |
else: | |
user_form = UserForm(instance=request.user) | |
profile_form = ProfileForm(instance=request.user.profile) | |
context = { | |
"user_form" : formshow, | |
"profile_form" : editform, | |
} | |
return render(request, "profile.html", context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment