本文整理匯總了Python中models.Category.__len__方法的典型用法代碼示例。如果您正苦於以下問題:Python Category.__len__方法的具體用法?Python Category.__len__怎麽用?Python Category.__len__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Category
的用法示例。
在下文中一共展示了Category.__len__方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_query
# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import __len__ [as 別名]
def run_query (request):
user = request.user
project = Project.objects.get(created_by=user.id)
query_name = request.POST.get("query_name", "")
from_date = request.POST.get("datepicker_from", "")
to_date = request.POST.get("datepicker_to", "")
language = request.POST.get("lan", "")
query = Query(name=query_name, venn=request.POST.get("query_logic", ""), from_date=parser.parse(from_date), to_date=parser.parse(to_date),
created=timezone.now(), created_by=user, owned_by=project)
query.save()
keywords = request.POST.get("keywords", "")
category = Category.objects.get(name="Keywords")
query_property = Query_properties(query=query, category=category, properties=keywords)
query_property.save()
twitter = request.POST.get("twitter", "")
category = Category.objects.get(name="Twitter")
query_property = Query_properties(query=query, category=category, properties=twitter)
query_property.save()
facebook = request.POST.get("facebook", "")
category = Category.objects.get(name="Facebook")
query_property = Query_properties(query=query, category=category, properties=facebook)
query_property.save()
brands = request.POST.get("brands", "")
try:
category = Category.objects.filter(name="brands")
except ValueError:
print ValueError.message
if category.__len__(): #exists already the category
category = category[0]
## otherwise create the category
else:
#print "is empty"
category = Category(name="brands")
category.save()
query_property = Query_properties(query=query, category=category, properties=brands)
query_property.save()
query_lan=Query_languages(query=query,language=language)
query_lan.save()
##handle dynamic properties
i = 0;
prop_value = "prop-value-%s" % i
prop_name = "prop-name-%s" % i
while request.POST.get(prop_value, ""):
property_name = request.POST.get(prop_name, "")
property_value = request.POST.get(prop_value, "")
try:
## try to find if the category already exists - in lowercase
category = Category.objects.filter(name=(str(property_name).lower()))
except ValueError:
#print ValueError.message
continue
if category.__len__(): #exists already the category
category = category[0]
## otherwise create the category
else:
category = Category(name=str(property_name).lower())
category.save()
## end store the properties in the category
query_property = Query_properties(query=query, category=category, properties=property_value)
query_property.save()
i += 1
prop_value = "prop-value-%s" % i
prop_name = "prop-name-%s" % i
return query.id