def user_profile_edit(request): if request.method == 'POST': u_fm = EditUserForm(request.POST, request.FILES, instance=request.user) if u_fm.is_valid(): u_fm.save() messages.success(request, "Profile Updated Successfully !!!") return redirect('profile') else: u_fm = EditUserForm(instance=request.user) return render(request, 'account/profile/editprofile.html', {'u_form': u_fm})
def edit(request): if request.method =="POST": form = EditUserForm(request.POST,instance = request.user) if form.is_valid(): user = form.save(instance = request.user) return HttpResponseRedirect('/home/') else: form = EditUserForm(instance = request.user ) return render(request,'account/edit.html',{'form':form})
def edit(request): if request.method == 'POST': user_form = EditUserForm(instance=request.user, data=request.POST) profile_form = ProfileEditForm( instance=request.user.profile, data=request.POST, files=request.FILES ) if user_form.is_valid and profile_form.is_valid: user_form.save() profile_form.save() messages.success(request, 'Profile updated Successfully!') else: messages.error(request, 'Error Updating your profile!') else: user_form = EditUserForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) return render(request, 'account/edit.html', {'user_form': user_form, 'profile_form': profile_form})
def settings_view(request): if request.method == 'POST': form = EditUserForm(request.POST, instance=request.user) student_form = EditStudentForm(request.POST, request.FILES, instance=request.user.student) if form.is_valid() and student_form.is_valid(): user_form = form.save() student = student_form.save(commit=False) student.user = user_form student.save() return redirect('account:settings') student_form = EditStudentForm(instance=request.user.student) form = EditUserForm(request.POST, instance=request.user) student_form.fields['studij'].widget.attrs = {'class': 'form-control'} context = { 'student_form': student_form, 'form': form, } return render(request, "account/settings.html", context)