本文整理匯總了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))