本文整理汇总了Python中products.models.Product.save方法的典型用法代码示例。如果您正苦于以下问题:Python Product.save方法的具体用法?Python Product.save怎么用?Python Product.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类products.models.Product
的用法示例。
在下文中一共展示了Product.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
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)
)
示例2: handle
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
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
示例3: publish_want_service
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
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')
示例4: list
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
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))
示例5: item_edit_service
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
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')
示例6: index
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
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))
示例7: list
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
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)
)
示例8: setUp
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
def setUp(self):
# création de l'admin
admin = User.objects.create_user('admin', password='adminpassword')
admin.is_staff = True
admin.save()
# création d'une catégorie
c1 = Category(name="Catégorie test 1")
c1.save()
# création des produits
f1 = File(open("media/tests/icon-test1.png", "rb"))
with f1:
p1 = Product(name="Prod1", description="desc", image=f1, category=c1)
p1.save()
f2 = File(open("media/tests/icon-test2.png", "rb"))
with f2:
p2 = Product(name="Prod2", description="desc", image=f2, category=c1)
p2.save()
示例9: list
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
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)
)
示例10: addProduct
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
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))
示例11: create
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
def create(self, validated_data):
products = validated_data.pop('products', None)
agent = Agent.objects.create(**validated_data)
agent.save()
if products is not None:
for product in products:
prod = Product()
prod.name = product.get('name')
prod.category = product.get('category')
prod.owner = product.get('owner')
prod.save()
agent.products.add(prod)
agent.save()
return agent
示例12: get_or_create_product
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
def get_or_create_product(asin):
"""
Checks the database for an existing ASIN. If not found, try to fetch it
using the Amazon Product API.
:return:
An instance of `products.models.Product`
"""
try:
product = Product.objects.get(asin=asin)
except:
amazon = AmazonAPI(settings.AWS_ACCESS_KEY_ID,
settings.AWS_SECRET_ACCESS_KEY,
settings.AWS_ASSOCIATE_TAG)
az = amazon.lookup(ItemId=asin)
product = Product(asin=asin, upc=az.upc, ean=az.ean,
description=az.title, image_url=az.large_image_url,
amazon_url=az.offer_url)
product.save()
generate_thumb.delay(product, '600x400')
generate_thumb.delay(product, '125x125')
product.manufacturer = az.get_attribute('Manufacturer')
product.brand = az.get_attribute('Brand')
product.model_number = az.get_attribute('Model')
product.mpn = az.mpn
product.part_number = az.part_number
product.sku = az.sku
product.isbn = az.isbn
product.length = az.get_attribute('ItemDimensions.Length')
product.width = az.get_attribute('ItemDimensions.Width')
product.height = az.get_attribute('ItemDimensions.Height')
product.weight = az.get_attribute('ItemDimensions.Weight')
product.save()
return product
示例13: addProductPOSTHandler
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
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
示例14: list
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
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)
)
示例15: setUp
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import save [as 别名]
def setUp(self):
prodcutgroup = ProductGroup(name="test product group")
prodcutgroup.save()
product = Product(product_variation="regular", goss_price="120.00", tax = "0.1200", stock=10, product_group = prodcutgroup)
product.save()
self.product = product