当前位置: 首页>>代码示例>>Python>>正文


Python ProfileForm.save_m2m方法代码示例

本文整理汇总了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})
开发者ID:abbad,项目名称:JamHubScratch,代码行数:18,代码来源:views.py

示例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})
开发者ID:abbad,项目名称:JamHubScratch,代码行数:18,代码来源:views.py

示例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})
开发者ID:nmasur,项目名称:creationdex,代码行数:19,代码来源:views.py


注:本文中的forms.ProfileForm.save_m2m方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。