本文整理汇总了Python中forms.ProductForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python ProductForm.save方法的具体用法?Python ProductForm.save怎么用?Python ProductForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ProductForm
的用法示例。
在下文中一共展示了ProductForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_edit
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def add_edit(request, id=None):
obj = None
if id:
obj = get_object_or_404(Product, pk=id)
if request.method == "POST":
form = ProductForm(request.POST, instance=obj)
if form.is_valid():
form.save()
messages.success(request, 'Record has been saved successfully.')
if id:
return HttpResponseRedirect(reverse("internal:products:index"))
return HttpResponseRedirect(".")
else:
messages.error(request, 'Failed to save record. Please correct the errors below.', extra_tags='danger')
else:
form = ProductForm(instance=obj)
context = {
'page_header': ("Edit Product ID: %s" % id) if id else "Add New Product",
'page_title': ("Edit Product ID: %s" % id) if id else "Add New Product",
'form': form
}
return render(
request,
'products/add_edit.html',
context
)
示例2: edit
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def edit(request, pk):
pd1 = get_object_or_404(Product,pk=id)
form = ProductForm(request.POST or None, instance = pd1)
if form.is_valid():
form.save()
t=get_template('ebook/forms.html')
c=RequestContext(request,locals())
return HttpResponse(t.render(c))
示例3: setUp
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def setUp(self):
self.product = {
'title':'My Book Title',
'description':'yyy',
'image_url':'http://google.com/logo.png',
'price':1
}
f = ProductForm(self.product)
f.save()
self.product['title'] = 'My Another Book Title'
示例4: my_products
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def my_products(request):
user = request.user
if request.method == 'POST':
form = ProductForm(request.POST)
if form.is_valid():
form.save()
else:
form = ProductForm()
companies = Company.objects.filter(owner=user)
products = Product.objects.filter(company__in=companies)
exchange_rate = get_rate_of_exchange()
return render(request, 'my_products.html', {'products': products, 'form': form, 'exchange_rate': exchange_rate})
示例5: new_product
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def new_product(request, pk):
form = ProductForm()
business_profile = get_object_or_404(BusinessProfile, pk=pk)
if request.method == 'POST' and request.user.is_authenticated():
form = ProductForm(request.POST)
if form.is_valid():
# check for duplicates
# check_duplicates(Product,
# form.cleaned_data['name'],
# form.cleaned_data['product_size'],
# business_profile)
product = form.save()
# attribute "business profile" to product
product.business_profile = business_profile
product.save()
messages.add_message(request, messages.INFO,
"You've created a product successfully. Please add raw materials used.")
return redirect('product_add_raw_material', pk=pk, id=product.id) #, id=product.id)
else:
# TODO -> handel errors here!
pass
return render_to_response('dashboard/new_product.html',
{'form': form},
RequestContext(request)
)
示例6: create
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def create(request):
if ( request.user.username=='' ):
Uform = AnonymousForm(prefix='ano')
Pform = ProductForm(prefix='prd')
if request.method == 'POST':
Pform = ProductForm(request.POST, request.FILES, prefix='prd')
Uform = AnonymousForm(request.POST, prefix='ano')
if Uform.is_valid() and Pform.is_valid():
FileUploadHandler(request.FILES['image'])
u = Uform.save()
p = Pform.save()
u.product_id = p.id
u.save()
return HttpResponseRedirect('/show/all/')
else:
Pform = ProductForm()
Uform = AnonymousForm()
args = {}
args.update(csrf(request))
args['Pform'] = Pform
args['Uform'] = Uform
return render_to_response('create_product_ano.html', args)
else:
if request.method == 'POST':
form = ProductForm(request.POST, request.FILES)
if form.is_valid():
FileUploadHandler(request.FILES['image'])
# u=User.objects.get(username=request.user.username)
obj = form.save(commit=False)
obj.user = request.user
obj.save()
return HttpResponseRedirect('/show/all/')
else:
form = ProductForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('create_product.html', args)
示例7: new
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def new(request):
form = ProductForm(request.POST or None)
if request.method == "POST":
form = ProductForm(request.POST)
if form.is_valid():
pd1 = form.save(created_by=request.user)
return redirect('product_last')
t = get_template('ebook/form.html')
c = RequestContext(request,locals())
return HttpResponse(t.render(c))
示例8: product_add
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def product_add(request):
if request.method == 'POST':
form = ProductForm(request.POST)
if form.is_valid():
p = form.save(commit=False)
p.sn = generate_sn(prefix = 'PROD')
p.save()
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize([p,], use_natural_foreign_keys=True))
else:
form = ProductForm()
return render_to_response('modal/main_form.html',{'action':'Add', 'module':module, 'form': form},context_instance=RequestContext(request))
示例9: my_product
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def my_product(request, slug=None):
product = get_object_or_404(Product, slug=slug)
if request.method == 'POST':
form = ProductForm(request.POST)
if form.is_valid():
updated_product = form.save(commit=False)
updated_product.id = product.id
updated_product.created = product.created
updated_product.save()
else:
form = ProductForm(instance=product)
return render(request, 'my_product.html', {'form': form, 'product': product})
示例10: edit_product
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def edit_product(request, product_id=0):
# Sets the form of product creation. If product_id is present, will use the product as form instance
if product_id:
try:
product = Product.objects.get(pk=product_id)
form = ProductForm(request.POST or None, instance=product)
except Product.DoesNotExist:
form = ProductForm(request.POST or None)
else:
form = ProductForm(request.POST or None)
if form.is_valid():
product = form.save()
return HttpResponseRedirect(reverse("products.views.products_list"))
return locals()
示例11: product_update
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def product_update(request):
if request.method == 'POST':
postdata = request.POST.copy()
try:
c = Product.objects.get(sn=postdata.pop('sn')[0])
except Product.DoesNotExist:
raise Http404
form = ProductForm(postdata, instance=c)
if form.is_valid():
p = form.save()
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize([p,], use_natural_foreign_keys=True))
else:
return HttpResponse('Invalid request.')
示例12: new_product
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def new_product(request):
if request.method == 'POST':
form = ProductForm(request.POST, request.FILES)
if form.is_valid():
product = form.save(commit=False)
product.seller = request.user
product.save()
request.session['message'] = 'Product successfully added'
return HttpResponseRedirect('/')
else:
context = retrieve_basic_info(request)
form = ProductForm()
context['form'] = form
return render(request, 'new_product.html', context)
return render(request, 'new_product.html', {'form': form})
示例13: add_product
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [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))
示例14: create_product
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def create_product(request):
form = ProductForm(request.POST or None)
if form.is_valid():
form.save()
form = ProductForm()
return render(request, 'marketapp/create_product.html', locals())
示例15: edit_product
# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import save [as 别名]
def edit_product(request, id):
product_instance = Product.objects.get(id = id)
form = ProductForm(request.POST or None, instance = product_instance)
if form.is_valid():
form.save()
return render(request, 'marketapp/edit_product.html', locals())