本文整理汇总了Python中products.models.Product类的典型用法代码示例。如果您正苦于以下问题:Python Product类的具体用法?Python Product怎么用?Python Product使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Product类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list
def list(request):
# Handle file upload
if request.method == "POST":
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Product(
user=request.user,
title=request.POST["title"],
docfile=request.FILES["docfile"],
active=request.POST["active"],
description=request.POST["description"],
quantity=request.POST["quantity"],
zip_Code=request.POST["zip_Code"],
address=request.POST["address"],
expire_date=request.POST["expire_date"],
)
newdoc.save()
# Redirect to the document list after POST
# return HttpResponseRedirect(reverse('products.views.list_detail'))
return redirect("products.views.post_detail_list", pk=newdoc.pk)
else:
form = DocumentForm() # A empty, unbound form
# Load documents for the list page
# documents = Document.objects.all()
# Render list page with the documents and the form
return render_to_response("products/list.html", {"form": form}, context_instance=RequestContext(request))
示例2: publish_want_service
def publish_want_service(request):
user = None
try:
user = Account.objects.get(id=request.session['user_id'])
except:
user = None
if not user:
return HttpResponse('false')
name = request.POST.get('name', '')
purpose = '3'
category = request.POST.get('category', '')
price = request.POST.get('price', '')
condition = '0'
phone = request.POST.get('phone', '')
qq = request.POST.get('qq', '')
campus = request.POST.get('campus', '')
content = request.POST.get('content', '')
validate_success = validate_publish(name, purpose, category, price, condition,
phone, qq, campus, content, '','want')
if not validate_success:
return HttpResponse('false')
big_imgs = 'big/big_default_want.jpg'
small_imgs = 'small/small_default_want.jpg'
product = Product(name=name, purpose=purpose, category=category, price=price,
condition=condition, phone=phone, qq=qq, campus=campus,
content=content, big_imgs=big_imgs, small_imgs=small_imgs,
owner=user)
product.save()
return HttpResponse('true')
示例3: list
def list(request):
document = Document.objects.filter(user_id=request.user.id).order_by("-docfile")[:1]
if request.method == "POST":
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Product(
user=request.user,
title=request.POST["title"],
docfile=request.FILES["docfile"],
active=request.POST["active"],
description=request.POST["description"],
quantity=request.POST["quantity"],
zip_Code=request.POST["zip_Code"],
address=request.POST["address"],
expire_date=request.POST["expire_date"],
)
newdoc.save()
return redirect("products.views.post_detail_list", pk=newdoc.pk)
else:
form = DocumentForm() # A empty, unbound form
# Load documents for the list page
return render_to_response(
"products/list.html", {"document": document, "form": form}, context_instance=RequestContext(request)
)
示例4: item_edit_service
def item_edit_service(request):
user = None
try:
user = Account.objects.get(id=request.session['user_id'])
except:
user = None
if not user:
return HttpResponse('false')
pid = request.POST.get('pid', '')
name = request.POST.get('name', '')
purpose = request.POST.get('purpose', '')
category = request.POST.get('category', '')
price = request.POST.get('price', 0)
condition = request.POST.get('condition', '')
phone = request.POST.get('phone', '')
qq = request.POST.get('qq', '')
campus = request.POST.get('campus', '')
content = request.POST.get('content', '')
files = request.FILES
file_list = list(request.FILES.keys())
try:
product = Product.objects.get(id=pid)
if not product.owner==user:
return HttpResponse('false')
except:
return HttpResponse('false')
validate_success = validate_publish(name, purpose, category, price, condition,
phone, qq, campus, content, files)
if not validate_success:
return HttpResponse('false')
# Get big_imgs and small_imgs
big_imgs, small_imgs = build_big_imgs_and_small_imgs(files)
# Save imgs
save_success = save_big_and_small_files(big_imgs, small_imgs, files)
if not save_success:
return HttpResponse('false')
product = Product(id=product.id, name=name, purpose=purpose, category=category, price=price,
condition=condition, phone=phone, qq=qq, campus=campus,
content=content, big_imgs=big_imgs, small_imgs=small_imgs,
owner=user)
product.save()
return HttpResponse('true')
示例5: setUp
def setUp(self):
self.ipn_record = IPNRecord(
transaction_id=1,
data='a=1',
)
self.ipn_record.save()
self.order = Order(
donation=100,
status=Order.SHOPPING_CART,
)
self.order.save()
self.product = Product(
name='Test Product',
slug='test-product',
price=500,
tax_deductible=50,
min_quantity=0,
max_quantity=10,
current_quantity=5,
status=Product.FOR_SALE,
)
self.product.save()
self.product_in_order = ProductInOrder(
order=self.order,
product=self.product,
quantity=1,
)
self.product_in_order.save()
示例6: list
def list(request):
if request.method == 'POST':
form = ProductForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Product(user = request.user, title = request.POST['title'], docfile = request.FILES['docfile'], active = request.POST['active'], description = request.POST['description'], quantity = request.POST['quantity'], zip_Code = request.POST['zip_Code'], address = request.POST['address'], expire_date = request.POST['expire_date'])
newdoc.save()
return HttpResponseRedirect(reverse('products:post_detail_list',args=(newdoc.pk,)))
else:
form = ProductForm() # A empty, unbound form
# Load documents for the list page
return render_to_response(
'products/list.html',
{ 'form': form},
context_instance=RequestContext(request)
)
示例7: handle
def handle(self, **options):
product_json = get_json()
for item in product_json:
# Try to find product - if it doesn't exist, create a new DB entry
try:
product = Product.objects.get(pk=item["id"])
except Product.DoesNotExist:
product = Product()
for key, value in item.items():
if not key in ["sizes"]:
if key in ["price", "price_old"]:
product.__dict__[key] = value.replace(",", ".")
elif key in ["kids", "kid_adult", "women", "free_porto"]:
product.__dict__[key] = int(value)
else:
product.__dict__[key] = value
product.from_json = True
product.save()
# Create a list of product sizes from the json
product_sizes = item["sizes"].split(",")
# Create product sizes, and add the sizes to the product
for item in product_sizes:
size, created = ProductSize.objects.get_or_create(title=item)
product.sizes.add(size)
return None
示例8: profile
def profile(request, username):
current_user_profile_url = get_current_user_profile_url(request)
profile_user = User.objects.get(username=username)
if not profile_user:
raise Http404
can_review = request.user.can_review(profile_user)
products = Product.listing().filter(user=profile_user)
products_sold_count = Product.objects.filter(user=profile_user, purchase__isnull=False).count()
return render_to_response("profiles/profile.html", locals(), context_instance=RequestContext(request))
示例9: addProduct
def addProduct(request, template_name='products/add_product.html'):
if request.method == 'POST':
addform = AddProductForm(request.POST)
if addform.is_valid():
data = addform.cleaned_data
product = Product(name=data['name'], price=data['price'], instock=data['units'],
ptype=data['ptype'], brand=data['brand'])
product.save()
addform = None
else:
addform = AddProductForm()
context = {'user': request.user, 'addform': addform}
return render_to_response(template_name, context, context_instance = RequestContext(request))
示例10: list
def list(request):
document = Document.objects.filter(user_id = request.user.id).order_by('-docfile')[:1]
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Product(user = request.user, title = request.POST['title'], docfile = request.FILES['docfile'], active = request.POST['active'], description = request.POST['description'], quantity = request.POST['quantity'], zip_Code = request.POST['zip_Code'], address = request.POST['address'], expire_date = request.POST['expire_date'])
newdoc.save()
return redirect('products.views.post_detail_list', pk=newdoc.pk)
else:
form = DocumentForm() # A empty, unbound form
# Load documents for the list page
return render_to_response(
'products/list.html',
{'document': document, 'form': form},
context_instance=RequestContext(request)
)
示例11: update_reset_candidates
def update_reset_candidates(products=Product.objects.all()):
"""Reset update bestbuys on list set of products"""
bestbuy_fields = Product.get_bestbuy_fields()
updates = {}
for fld in bestbuy_fields :
updates['%s' %fld] = 0
#apply the updates
product_update = products.update(**updates)
print "PRODUCT_COUNT= %s" %product_update
示例12: addProductPOSTHandler
def addProductPOSTHandler(post_request):
product_exists = True
try:
brand = Brand.objects.get(name=post_request['brand'])
except Brand.DoesNotExist:
brand = Brand(name=post_request['brand'])
brand.save()
product_exists = False
try:
category = Category.objects.get(name=post_request['category'])
except Category.DoesNotExist:
category = Category(name=post_request['category'])
category.save()
product_exists = False
try:
ptype = ProductType.objects.get(name=post_request['ptype'])
except ProductType.DoesNotExist:
ptype = ProductType(name=post_request['ptype'], category=category)
ptype.save()
product_exists = False
try:
product = Product.objects.get(name=post_request['name'])
product = []
except Product.DoesNotExist:
if not product_exists:
product = Product(
name=post_request['name'],
price=post_request['price'],
instock=post_request['units'],
brand=brand,
ptype=ptype)
product.save()
return product
示例13: list
def list(request):
# Handle file upload
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Product(user = request.user, title = request.POST['title'], docfile = request.FILES['docfile'], active = request.POST['active'], quantity = request.POST['quantity'], zip_Code = request.POST['zip_Code'], address = request.POST['address'], date_created = request.POST['date_created'],date_Update = request.POST['date_Update'], expire_date = request.POST['expire_date'])
newdoc.save()
# Redirect to the document list after POST
#return HttpResponseRedirect(reverse('products.views.list_detail'))
return redirect('products.views.post_detail_list', pk=newdoc.pk)
else:
form = DocumentForm() # A empty, unbound form
# Load documents for the list page
#documents = Document.objects.all()
# Render list page with the documents and the form
return render_to_response(
'products/list.html',
{'form': form},
context_instance=RequestContext(request)
)
示例14: index
def index(request, product_uuid=None):
product = None if not product_uuid else Product.objects.get(uuid=product_uuid)
if request.method == 'POST':
p = Product()
p.name = request.POST.get('name', None)
p.description = request.POST.get('description', None)
p.image_url = request.POST.get('image_url', None)
p.url = request.POST.get('url', None)
p.author = request.user if request.user.id else None
p.save()
if not product and Product.objects.count() != 0:
product = Product.objects.order_by('-created')[0]
ctx = {
'product': product,
'latest': Product.objects.order_by('-created')[:5],
}
return render_to_response('index.html', ctx, context_instance=RequestContext(request))
示例15: ajax_products_analysis
def ajax_products_analysis(request):
data = dict()
switcher = request.GET.get('analysis')
queryset = Product.my_query.active_warehouse()
queryset = Product.filters_data(request, queryset)
queryset_analysis = [0, 0, 0] # total_qty, #total_warehouse_value, #total_sell_value
if switcher == 'warehouse_analysis':
queryset_analysis[0] = queryset.aggregate(Sum('qty'))['qty__sum'] if queryset else 0
queryset_analysis[1] = queryset.aggregate(total=Sum(F('qty') * F('price_buy')))['total'] if queryset else 0
queryset_analysis[2] = queryset.aggregate(total=Sum(F('qty') * F('final_price')))['total'] if queryset else 0
data['results'] = render_to_string(request=request,
template_name='report/ajax/warehouse/ajax_warehouse_analysis.html',
context={'queryset_analysis': queryset_analysis,
'currency': CURRENCY,
'switcher': switcher
}
)
if switcher == 'vendor_analysis':
vendor_analysis = queryset.values('supply__title').annotate(total_ware_price=Sum(F('qty')*F('final_price')),
total_sell_price=Sum(F('qty')*F('price_buy'))
).order_by('supply__title')
data['results'] = render_to_string(request=request,
template_name='report/ajax/warehouse/ajax_warehouse_analysis.html',
context={'vendor_analysis': vendor_analysis,
'currency': CURRENCY,
'switcher': switcher,
}
)
if switcher == "sells_analysis":
sells_items = RetailOrderItem.objects.filter(title__in=queryset) if queryset else None
sells_analysis = sells_items.values('title__title').annotate(total_sells=Sum(F('qty')),
incomes=Sum(F('qty')*F('final_price'))
).order_by('-incomes')[:30]
data['results'] = render_to_string(request=request,
template_name='report/ajax/warehouse/ajax_warehouse_analysis.html',
context={ 'sells_analysis': sells_analysis,
'currency': CURRENCY,
'switcher': switcher
}
)
if switcher == 'buy_analysis':
pass
return JsonResponse(data)