本文整理汇总了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))