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


Python ProductForm.save_m2m方法代码示例

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


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

示例1: add_product

# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save_m2m [as 别名]
def add_product (request, template_name="pdcts/add.html"):
        request.breadcrumbs(("Submit a Product"),request.path_info)
	page_title = 'Submission'

    	'''try:
        	profile = request.user.get_profile()
    	except UserProfile.DoesNotExist:
       		profile = UserProfile(user=request.user)
        	profile.save() '''

	if request.method =='POST':
		form = ProductForm (request.POST, request.FILES)

		email_subject = 'Approve a Product'
		email_body = "Hello Administrator, \n\nThis is a My Campuser alert for products that have been submitted and are awaiting your approval.\n\nLogin to the admin panel to activate/approve these products\n\nRegards,\nMy Campuser Team"

		if form.is_valid():
			add = form.save(commit=False)
			add.user = request.user
			product_name = request.POST.get('product_name')
			add.product_name = product_name.title()
			add.save()
			form.save_m2m()
			send_mail(email_subject, email_body, '[email protected]' , ['[email protected]'])

	             	reputation = User_Reputation.objects.filter(user = request.user)

	             	if reputation:
				r = User_Reputation.objects.get(user = request.user)
				nR = r.reputation
	              	else:
		   		r = User_Reputation()
		              	r.user = request.user
		             	r.reputation = 0.5
		                r.entity_alpha = 0.5
		               	r.entity_beta = 0.5
		               	r.votes = 0
		               	r.save()                        

			return HttpResponseRedirect('/success/')
	else:
		form = ProductForm()
	return render_to_response(template_name, locals(), context_instance = RequestContext(request))
开发者ID:mwotil,项目名称:nuaza,代码行数:45,代码来源:views.py


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