本文整理汇总了Python中models.Item.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Item.objects方法的具体用法?Python Item.objects怎么用?Python Item.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.objects方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_favorite
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import objects [as 别名]
def get_favorite(id):
from models import Favorite, Item
favorite_items = []
obj = Favorite.objects(user_id=id)
if obj:
favorite = obj.get()
for article_id in favorite.article_list:
item = Item.objects(artical_id=article_id).get()
favorite_items.append(item)
return dumps(convert_items_to_list(favorite_items))
示例2: index
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import objects [as 别名]
def index(page_number=1):
""" Display a paginated home page of items, ordered by posting date.
Implement this when you understand it fully:
http://flask.pocoo.org/snippets/44/
"""
# Clean up the page number. I found out that Python's 'pass-by-object'
# when writing this simple method and my head's a little... shaken.
page_number = enforce_integer(page_number)
# Quick calculations for pagination
number_of_items = Item.objects().count()
number_of_pages = int(ceil(number_of_items / float(items_per_page)))
start = (page_number - 1) * items_per_page
end = start + items_per_page
# Use array splicing (docs-recommended over start() and limit())
# to paginate results
return render_template("index.html",
items=Item.objects[start:end].order_by('-posted'), **locals())
示例3: search_by_tags
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import objects [as 别名]
def search_by_tags(tagname=None):
tag_list = tagname.strip().split("+")
return render_template("index.html", items=Item.objects(tags__in = tag_list))
示例4: search_by_type
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import objects [as 别名]
def search_by_type(post_type=None):
if post_type in [ short_type for short_type, long_type in post_types]:
return render_template("index.html", items=Item.objects(post_type__exact = post_type))
else:
abort(404)
示例5: tearDown
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import objects [as 别名]
def tearDown(self):
BorrowPast.objects().delete()
Item.objects().delete()
CampusLocation.objects().delete()
User.objects().delete()
UserGroup.objects().delete()