本文整理汇总了Python中products.models.Product.name方法的典型用法代码示例。如果您正苦于以下问题:Python Product.name方法的具体用法?Python Product.name怎么用?Python Product.name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类products.models.Product
的用法示例。
在下文中一共展示了Product.name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveProductData
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import name [as 别名]
def saveProductData(request, productForm):
product = Product()
product.name = productForm.cleaned_data['name']
product.description = productForm.cleaned_data['description']
product.q_amount = productForm.cleaned_data['q_amount']
user = request.user
product.id_owner = user
product.start_datetime = str(datetime.now())
product.end_datetime = str(datetime.now())
product.follower_qty = 0
product.visit_qty = 0
product.img = uuid.uuid1().hex
product.featured_time = 0;
product.active = 1
return product
示例2: index
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import name [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))
示例3: create
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import name [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
示例4: handle
# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import name [as 别名]
def handle(self, *args, **options):
"""
Scrapes and stores product information
"""
# get beer page html and make soup object
html = urllib2.urlopen(TOP_URL + "/beers/search")
soup_beers = BeautifulSoup(html)
# find all beers
beers = soup_beers.find_all("a", "brand-link")
for beer in beers:
# get beer page and make soup object
beer_url = beer["href"]
beer_html = urllib2.urlopen(TOP_URL + beer_url)
soup_beer = BeautifulSoup(beer_html)
# get sizes
beer_products = soup_beer.find_all("table", "brand-pricing")
# get propertis and valus and merge them into dict
labels = soup_beer.dl.find_all("dt")
details = soup_beer.dl.find_all("dd")
beer_details = dict(zip(labels,details))
# get name and image
beer_name = soup_beer.find("div", "only-desktop").find("h1", "page-title").get_text()
beer_image = soup_beer.find("div","brand-image").img["src"]
# get country and type
beer_attributes = soup_beer.find("p","introduction").find_all("span")
beer_attributes = beer_attributes[::-1]
beer_country = beer_attributes[0].get_text()
beer_type = beer_attributes[1].get_text()
# loop through beer products
for beer_product in beer_products:
beer_containers = beer_product.find_all("tbody")
# loop through container tables
for beer_container in beer_containers:
beer_sizes = beer_container.find_all("tr")
# loop through container sizes
for beer_size in beer_sizes:
# get product information
beer_ids = beer_size.a["href"].split('=')[1]
beer_id = beer_ids.split('-')[0]
print beer_id
beer_product_id = beer_ids.split('-')[1]
# Comment to disable monitoring
beer_product_size = beer_size.find("td","size").get_text()
beer_product_price = beer_size.find("td","price").get_text()
# check if product exists
# NOTE: used this custom solution because django get_or_create
# doesn't play nice with custom primary keys
try:
product_entry = Product.objects.get(product_id=int(beer_product_id.strip()))
except:
product_entry = Product()
# set fields
product_entry.name = beer_name.strip()
product_entry.size = beer_product_size.strip()
product_entry.beer_id = int(beer_id.strip())
product_entry.product_id = int(beer_product_id.strip())
product_entry.image_url = beer_image.strip()
product_entry.country = beer_country.strip()
product_entry.type = beer_type.strip()
# set product attributes
# NOTE: this code was created befor the beer store redesign
# it still works but some items no longer exist so they were
# temporarily omitted from the serializer
for key, value in beer_details.iteritems():
attr = key.get_text()[:-1]
val = value.get_text()
if attr == 'Category':
product_entry.category = val
if attr == 'Alcohol Content (ABV)':
product_entry.abv = float(val[:-1])
if attr == 'Style':
product_entry.style= val
if attr == 'Attributes':
product_entry.attributes= val
if attr == 'Brewer':
product_entry.brewer= val
# update pricing info
try:
product_entry.price = float(beer_product_price.strip()[1:])
#.........这里部分代码省略.........