当前位置: 首页>>代码示例>>Python>>正文


Python BlogPost.put方法代码示例

本文整理汇总了Python中blog.models.BlogPost.put方法的典型用法代码示例。如果您正苦于以下问题:Python BlogPost.put方法的具体用法?Python BlogPost.put怎么用?Python BlogPost.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在blog.models.BlogPost的用法示例。


在下文中一共展示了BlogPost.put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_blog_post

# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import put [as 别名]
def update_blog_post(title, content, is_published, blog_post_id=None):
    if not blog_post_id:
        p = BlogPost()
    else:
        p = get_blog_post(blog_post_id)
    p.title = title
    p.content = content
    p.is_published = bool(is_published)
    p.put()
    return p
开发者ID:tb123,项目名称:tushar.bhatia.io,代码行数:12,代码来源:utils.py

示例2: insert_post_with_unique_key

# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import put [as 别名]
def insert_post_with_unique_key(post_dict):
    """
    First we try to add the blog post with key name equal to the slug of the
    post's title.
    If this key is already taken we append a random two characters and repeat
    until a free key is generated. The blog post is then saved with this new
    key.

    In all queries we specify the parent as the blog with name the author's
    nickname. This means that all queries run on a single entity group so we
    don't have to use a cross-group transaction. Also this means two users can
    be posting at the same time as the transaction only locks the entity group
    corresponding to the current logged in user.
    """
    key_name_base = unicode(slugify(post_dict['title']))
    key_name = key_name_base
    parent_key = blog_key(post_dict['author'])
    while BlogPost.get_by_key_name(key_name, parent=parent_key):
        key_name = '%s-%s' % (key_name_base, ''.join([random.choice(
            string.ascii_letters + string.digits) for i in range(2)]))
    post = BlogPost(parent=parent_key, key_name=key_name, **post_dict)
    post.put()
    return post
开发者ID:bensums,项目名称:blog-exercise,代码行数:25,代码来源:views.py


注:本文中的blog.models.BlogPost.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。