Skip to content

Instantly share code, notes, and snippets.

@walison17
Last active May 8, 2018 00:59
Show Gist options
  • Save walison17/8e5cbc5b47aa2420e4a80e2a45fbaf8c to your computer and use it in GitHub Desktop.
Save walison17/8e5cbc5b47aa2420e4a80e2a45fbaf8c to your computer and use it in GitHub Desktop.
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