本文整理汇总了Python中forms.ProfileForm.save_m2m方法的典型用法代码示例。如果您正苦于以下问题:Python ProfileForm.save_m2m方法的具体用法?Python ProfileForm.save_m2m怎么用?Python ProfileForm.save_m2m使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ProfileForm
的用法示例。
在下文中一共展示了ProfileForm.save_m2m方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save_m2m [as 别名]
def edit_profile(request):
profile = Profile.objects.get(user = request.user)
if request.method == 'POST':
profileForm = ProfileForm(request.POST, instance = profile)
if profileForm.is_valid() and request.user.is_authenticated():
profile = profileForm.save(commit = False)
profile.user = request.user
profile.is_active = True
profile.save()
profileForm.save_m2m()
return HttpResponseRedirect('profile/' + request.user.username)
else:
return render(request, 'editProfile.html', {'profileForm': profileForm})
else:
profileForm = ProfileForm(instance = profile)
return render(request, 'editProfile.html', {'profileForm': profileForm})
示例2: create_profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save_m2m [as 别名]
def create_profile(request):
# REMEMBER TO HANDLE UNAUTHENTICATED USERS
if request.method == 'POST':
profileForm = ProfileForm(request.POST)
if profileForm.is_valid() and request.user.is_authenticated():
profile = profileForm.save(commit = False)
profile.user = request.user
profile.is_active = True
profile.save()
profileForm.save_m2m()
return HttpResponseRedirect('home.html')
else:
return render(request, 'createProfile.html', {'form': profileForm})
else:
profileForm = ProfileForm()
return render(request, 'createProfile.html', {'form': profileForm})
示例3: editprofile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save_m2m [as 别名]
def editprofile(request):
basic = get_basic(request)
try:
prof = Profile.objects.get(user=User.objects.get(id=request.user.id))
except ObjectDoesNotExist:
prof = Profile()
if request.method == 'POST':
form = ProfileForm(request.POST, request.FILES, instance=prof)
if form.is_valid():
obj = form.save(commit=False)
obj.user = User.objects.get(id=request.user.id)
obj.save()
form.save_m2m()
return HttpResponseRedirect('/profile?id=' + str(request.user.id))
else:
form = ProfileForm(instance=prof)
return render(request, 'editprofile.html', {'form': form, 'basic': basic})