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


Python Blog.tags方法代码示例

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


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

示例1: testdb_init

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import tags [as 别名]
def testdb_init():
    # db clear
    t1 = Tag(title="emacs")
    t2 = Tag(title="python")
    t1.put()
    t2.put()

    c1 = Category(title='program')
    c2 = Category(title='edit')
    c1.put()
    c2.put()

    b1 = Blog(title='first blog')
    b1.context = "this is my first blog, hello world"
    b1.put()
    b2 = Blog(title="second blog")
    b2.context = "this is my second blog, hello python"
    b2.tags = [t1.key, t2.key]
    b2.put()
    b3 = Blog(title="third blog")
    b3.context = "this is my third blog, hello python"
    b3.tags = [t1.key,]
    b3.category = c2.key
    b3.put()
    b4 = Blog(title="fourth blog")
    b4.context = "this is my fourth blog, hello python"
    b4.tags = [t2.key,]
    b4.category = c1.key
    b4.put()
开发者ID:hackrole,项目名称:gblog,代码行数:31,代码来源:fts.py

示例2: save_blog

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import tags [as 别名]
def save_blog(request):
    bid = request.POST.get("bid", "").strip()
    title = request.POST.get("title", "").strip()
    category = request.POST.get("category", "").strip()
    content = request.POST.get("content", "").strip()

    if len(title) < 3 or len(content) < 4:
        return HttpResponseRedirect("/")

    if bid:
        try:
            bid = int(bid)
            # print 'bid: ', bid
        except:
            # print 'error bid: ', bid
            return HttpResponseRedirect("/")
        blog_set = Blog.objects.filter(id=bid)
        if blog_set:
            blog = blog_set[0]
        else:
            return HttpResponseRedirect("/")
    else:
        blog = Blog()
    blog.tags = "blog"
    blog.title = title
    blog.content = content
    blog.save()

    list_category = category.lower().split(",")
    for c in list_category:
        c = c.strip()
        if not c:
            continue
        cate_set = Category.objects.filter(name=c)
        if cate_set:
            # print 'category exist: ', c
            blog.categorys.add(cate_set[0])
        else:
            # print 'new category: ', c
            _category = Category(name=c)
            _category.save()

            blog.categorys.add(_category)

    return HttpResponseRedirect("/blog/%d.html" % blog.id)
开发者ID:xeon2007,项目名称:mycode,代码行数:47,代码来源:views.py

示例3: save_blog

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import tags [as 别名]
def save_blog(request):
    bid     = request.POST.get('bid', '').strip()
    title   = request.POST.get('title', '').strip()
    category= request.POST.get('category', '').strip()
    content = request.POST.get('content', '').strip()
    print request.POST
    if len(title) < 3 or len(content) < 4:
        print content
        print "title or content not correct"
        return HttpResponseRedirect('/')
    
    if bid:
        try:
            bid = int(bid)
        except:
            return HttpResponseRedirect('/')
        blog_set = Blog.objects.filter(id=bid)
        if blog_set:
            blog = blog_set[0]
        else:
            return HttpResponseRedirect('/')
    else:
        blog = Blog()
    blog.tags = 'blog'
    blog.title = title
    blog.content = content
    blog.save()

    list_category = category.lower().split(',')
    blog.categorys.clear()
    for c in list_category:
        c = c.strip()
        if not c:
            continue
        cate_set = Category.objects.filter(name=c)
        if cate_set:
            blog.categorys.add(cate_set[0])
        else:
            _category = Category(name=c)
            _category.save()
            
            blog.categorys.add(_category)

    return HttpResponseRedirect('/blog/%d.html'%blog.id)
开发者ID:lvshuchengyin,项目名称:mycode,代码行数:46,代码来源:views.py


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