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


Python ProjectForm.save_m2m方法代码示例

本文整理汇总了Python中forms.ProjectForm.save_m2m方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectForm.save_m2m方法的具体用法?Python ProjectForm.save_m2m怎么用?Python ProjectForm.save_m2m使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.ProjectForm的用法示例。


在下文中一共展示了ProjectForm.save_m2m方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: newproject

# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import save_m2m [as 别名]
def newproject(request):
	basic = get_basic(request)
	if request.method == 'POST':
		form = ProjectForm(request.user, request.POST, request.FILES)
		if form.is_valid():
			obj = form.save(commit=False)
			obj.user = request.user
			obj.save()
			form.save_m2m()
			return HttpResponseRedirect('/project?id=' + str(obj.id))
	else:
		proj = Project()
		proj.user = request.user
		form = ProjectForm(request.user, instance=proj)
	return render(request, 'newproject.html', {'form': form, 'basic': basic})
开发者ID:nmasur,项目名称:creationdex,代码行数:17,代码来源:views.py

示例2: add_project

# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import save_m2m [as 别名]
def add_project(request):
	# REMEMBER TO HANDLE UNAUTHENTICATED USERS
	if request.method == 'POST':
		projectForm = ProjectForm(request.POST)
		if projectForm.is_valid() and request.user.is_authenticated():
			project = projectForm.save(commit = False) 
			project.creator = request.user
			project.soundCloud = getIFrameSrc(projectForm.cleaned_data['soundCloud'])
			project.is_active = True
			project.save()
			projectForm.save_m2m()
			return HttpResponseRedirect('profile/' + request.user.username)
		else: 
			return render(request, 'addProject.html', {'projectForm': projectForm})
	else: 
		projectForm = ProjectForm()
		return render(request, 'addProject.html', {'projectForm': projectForm})
开发者ID:abbad,项目名称:JamHubScratch,代码行数:19,代码来源:views.py

示例3: editproject

# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import save_m2m [as 别名]
def editproject(request):
	basic = get_basic(request)
	try:
		proj = Project.objects.get(id=request.GET['id'])
		# Prevent from editing another user's project
		if proj.user.id != request.user.id:
			raise AssertionError
	except (ObjectDoesNotExist, KeyError, AssertionError):
		return HttpResponseRedirect('/editprojects/')
	if request.method == 'POST':
		form = ProjectForm(request.user, request.POST, request.FILES, instance=proj)
		if form.is_valid():
			obj = form.save(commit=False)
			obj.user = request.user
			obj.save()
			form.save_m2m()
			return HttpResponseRedirect('/project?id=' + str(obj.id))
	else:
		form = ProjectForm(request.user, instance=proj)
	return render(request, 'editproject.html', {'form': form, 'basic': basic})
开发者ID:nmasur,项目名称:creationdex,代码行数:22,代码来源:views.py

示例4: edit_project

# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import save_m2m [as 别名]
def edit_project(request, project_id):
	if not request.user.is_authenticated(): 
		return render(request, 'test.html')
	
	# get the object 
	try:
		project = Project.objects.get(id = project_id)
	except :
		raise Http404
	 
	if request.method == 'POST':
		projectForm = ProjectForm(request.POST, instance = project)
		if projectForm.is_valid() and request.user.is_authenticated():
			project = projectForm.save(commit = False)
			project.user = request.user
			project.save()
			projectForm.save_m2m()
			return HttpResponseRedirect('/profile/' + request.user.username)
		else:
			return render(request, 'editProject.html', {'projectForm': projectForm})
	else:
		projectForm = ProjectForm(instance = project)
		return render(request, 'editProject.html', {'projectForm': projectForm})
开发者ID:abbad,项目名称:JamHubScratch,代码行数:25,代码来源:views.py


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