当前位置: 首页>>代码示例>>Python>>正文


Python Product.save方法代码示例

本文整理汇总了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)
    )
开发者ID:brajvit,项目名称:echaritykanpur,代码行数:28,代码来源:views.py

示例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
开发者ID:rulzart,项目名称:sample,代码行数:27,代码来源:build_db.py

示例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')
开发者ID:yangcheng470,项目名称:ewu-v4,代码行数:34,代码来源:index.py

示例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))
开发者ID:richavit,项目名称:Echarity_final_project2,代码行数:31,代码来源:views.py

示例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')
开发者ID:karlind,项目名称:ewu-v4,代码行数:52,代码来源:index.py

示例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))
开发者ID:ehazlett,项目名称:windowshop,代码行数:19,代码来源:views.py

示例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)
    )
开发者ID:richavit,项目名称:vitcpanda,代码行数:19,代码来源:views.py

示例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()
开发者ID:pchmn,项目名称:djangorest-base,代码行数:19,代码来源:tests.py

示例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)
    )
开发者ID:vinayvit,项目名称:echarity,代码行数:20,代码来源:views.py

示例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))
开发者ID:brunodea,项目名称:SiteVendas,代码行数:20,代码来源:views.py

示例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
开发者ID:ianjuma,项目名称:jaza,代码行数:21,代码来源:serializers.py

示例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
开发者ID:phrac,项目名称:onemgin,代码行数:41,代码来源:amazon_utils.py

示例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
开发者ID:hstefan,项目名称:SiteVendas,代码行数:41,代码来源:views.py

示例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)
    )
开发者ID:brajeshvit,项目名称:EcharitycompletedonateandHistory11dec15,代码行数:25,代码来源:views.py

示例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
开发者ID:hshafy,项目名称:ecomapi,代码行数:8,代码来源:tests.py


注:本文中的products.models.Product.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。