本文整理汇总了Python中core.models.Blog.query方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.query方法的具体用法?Python Blog.query怎么用?Python Blog.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.models.Blog
的用法示例。
在下文中一共展示了Blog.query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_context_data
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import query [as 别名]
def get_context_data(self, **kwargs):
context = super(BlogView, self).get_context_data(**kwargs)
default_blog = Blog.query().get()
context['blog'] = default_blog
if default_blog:
context['posts'] = Blog.get_all_posts(default_blog.key.id())
return context
示例2: initialise_db
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import query [as 别名]
def initialise_db():
# Create an ancestor for all of our Posts to ensure consistency when manipulating Posts
blog_instance = Blog.query().get()
if not blog_instance:
blog_instance = Blog()
blog_instance.put()
# Create Users
if not User.query().fetch():
User(
username='admin',
password='admin' # TODO - obfuscate this
).put()
示例3: get_blog_key
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import query [as 别名]
def get_blog_key():
# Return our Blog key. There should only be one instance of Blog. This is used as an ancestor to all Posts.
return Blog.query().get().key
示例4: test_blog_create
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import query [as 别名]
def test_blog_create(self):
""" we can create """
res = self.c.post('/blog', {'title': 'Sample Blog 1', 'description': 'Sample Description'})
self.assertEqual(len(Blog.query().fetch()), 2)
示例5: test_blog_delete
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import query [as 别名]
def test_blog_delete(self):
""" we can destroy"""
res = self.c.delete('/blog/delete/{0}'.format(self.blog_id))
self.assertEqual(res.status_code, 200)
self.assertEqual(len(Blog.query().fetch()), 0)
示例6: test_blog_get
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import query [as 别名]
def test_blog_get(self):
""" ensure blog exist """
res = self.c.get('/')
self.assertEqual(res.context_data['blog'], Blog.query().get())