本文整理汇总了Python中models.Tag.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.get_by_key_name方法的具体用法?Python Tag.get_by_key_name怎么用?Python Tag.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tag
的用法示例。
在下文中一共展示了Tag.get_by_key_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tag_page
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get_by_key_name [as 别名]
def tag_page(request, tag, page):
"""
Lists documents with a certain tag.
"""
# Check if the page is cached
cache_key = 'tag_page:%s-%s' % (tag, page)
cached_response = get_cached_response(request, cache_key)
if cached_response:
return cached_response
# Get the data
tag = Tag.get_by_key_name(tag)
if not tag:
raise Http404
object_list = Document.all().filter('tags =', tag.key()).filter("is_published =", True)
paginator = Paginator(object_list, 10)
# Limit it to thise page
try:
page = paginator.page(page)
except (EmptyPage, InvalidPage):
raise Http404
# Create a response and pass it back
context = {
'headline': 'Documents tagged ‘%s’' % tag.title,
'object_list': page.object_list,
'page_number': page.number,
'has_next': page.has_next(),
'next_page_number': page.next_page_number(),
'next_page_url': '/tag/%s/page/%s/' % (tag.title, page.next_page_number())
}
return direct_to_template(request, 'document_list.html', context)
示例2: list_tag_post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get_by_key_name [as 别名]
def list_tag_post(request,tag_name):
tag = Tag.get_by_key_name(tag_name)
if not tag:
raise Http404
# tag.getPosts().order('-create_time')
tag.post_list = tag.getPosts()
return object_list(request, queryset=tag.post_list, allow_empty=True,
template_name='list_tag_post.html', extra_context={'is_author': is_author(), 'is_author': is_author(), 'tag': tag},
paginate_by=settings.POST_LIST_PAGE_SIZE)