django edit profile

Solutions on MaxInterview for django edit profile by the best coders in the world

showing results for - "django edit profile"
Mika
01 May 2016
1def profile_edit(request):
2  	#Get the profile
3    profile = Profile.objects.get(user=request.user)
4    
5    if request.method == 'POST':
6        userform = UserUpdateForm(request.POST,instance=request.user)
7        profileform = ProfileUpdateForm(request.POST,request.FILES,instance=profile)
8        
9        if userform.is_valid and profileform.is_valid:
10            userform.save()
11            new_profile = profileform.save(commit=False)
12            new_profile.user = request.user
13            new_profile.save()
14            return redirect('/accounts/profile')
15    else:
16        userform = UserUpdateForm(instance=request.user)
17        profileform = ProfileUpdateForm(instance=profile)
18    
19    return render(request,'accounts/profile_edit.html',context={'form1':userform,'form2':profileform})