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


Python BlogPost.save方法代码示例

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


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

示例1: add_post

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import save [as 别名]
def add_post(request):
    if request.method == 'POST':
        form = BlogPostForm(request.POST)

        if form.is_valid():
            new_post = BlogPost(
                title=form.cleaned_data['title'],
                content=form.cleaned_data['content'],
                published=True,
                author=request.user
            )

            new_post.save()

            return redirect('view_posts', post_id=new_post.id)
    else:
        form = BlogPostForm()

    return render(
        request,
        'add_post.html',
        {
            'form': form,
        }
    )
开发者ID:fscherf,项目名称:django_workshop,代码行数:27,代码来源:views.py

示例2: setUp

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import save [as 别名]
    def setUp(self):
        # Every test needs access to the request factory.
        self.user = get_user_model().objects.create_user(username='bmelton', email='[email protected]', password='top_secret')
        self.factory = APIRequestFactory()

        blog1 = BlogPost(id=1, author=self.user, title="Test Blog Title 1", body="This is a test blog article.")
        blog1.save()

        blog2 = BlogPost(id=2, author=self.user, title="Test Blog Title 2", body="This is another test blog article.")
        blog2.save()
开发者ID:crobertsbmw,项目名称:pants-party,代码行数:12,代码来源:tests.py

示例3: post

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import save [as 别名]
    def post(self):
        form = BlogPostForm(self.request.POST)

        if form.validate():
            post = BlogPost(**form.data)
            post.save()
            self.redirect_to("admin-blog-post-edit-extra", post_id = post.key().id(), extra="saved")

        return {
            "admin_section": "admin-blog-posts-new",
            "form": form,
        }
开发者ID:ashenwolf,项目名称:skoll-tech-portfolio,代码行数:14,代码来源:views_admin.py

示例4: add_post

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import save [as 别名]
def add_post(request):
    context = RequestContext(request)
    if request.method == 'POST':
        form = BlogPostForm(request.POST) 
        if form.is_valid():
            blog = BlogPost()
            blog.author = request.user
            blog.title = request.POST['title']
            blog.bodytext = request.POST['bodytext']
            blog.save()
            messages.add_message(request, SUCCESS, 'Post Added')
            
            return HttpResponseRedirect('/main/blog/')
        else:
            messages.add_message(request, SUCCESS, 'Enter a valid Post')
            return HttpResponseRedirect('/main/add/')
    else:
        form = BlogPostForm() 
    return render_to_response('blog/add.html', {'form': form}, context)
开发者ID:ranselmojr,项目名称:MyFirstWebApp,代码行数:21,代码来源:views.py

示例5: loaddir

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import save [as 别名]
def loaddir(directory, clear=False):
    if clear:
        BlogPost.objects.all().delete()

    queue = os.listdir(directory)
    while queue:
        next = queue.pop()
        if next[0] == '.': continue
        if next in ('template.rst', 'template'): continue
        next = path.join(directory, next)
        if path.isdir(next):
            queue.extend([
                path.join(next,f) for f in os.listdir(next)
                ])
            continue

        filecontent = file(next).read()
        parts = filecontent.split('\n---\n', 1)
        fields, content = parts
        if len(parts) != 2:
            raise IOError('gitcms.blog.load: expected "---" separator in file %s' % next)
        fields = yaml.load(fields)
        fields['timestamp'] = parsedatetime(fields['timestamp'])
        fields['year_month_slug'] = time.strftime('%%Y/%%B/%s' % fields['slug'], fields['timestamp'])
        fields['timestamp'] = time.strftime('%Y-%m-%d %H:%M', fields['timestamp'])
        fields['content'] = preprocess_rst_content(content)
        categories = fields.get('categories', '')
        if 'categories' in fields: del fields['categories']
        ptags = []
        if categories:
            for c in categories.split():
                ptags.append(tag_for(c))
        # if we arrived here and no errors, then it is safe
        # to add our post.
        #
        P = BlogPost(**fields)
        P.save()
        for t in ptags:
            P.tags.add(t)
开发者ID:pombredanne,项目名称:django-gitcms,代码行数:41,代码来源:load.py

示例6: loaddir

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import save [as 别名]
def loaddir(directory, clear=False):
    if clear:
        BlogPost.objects.all().delete()

    queue = os.listdir(directory)
    while queue:
        next = queue.pop()
        if next[0] == '.':
            continue

        if next in ('template.rst', 'template'):
            continue

        next = os.path.join(directory, next)
        if os.path.isdir(next):
            queue.extend([os.path.join(next, f) for f in os.listdir(next)])
            continue

        filecontent = file(next).read()
        parts = filecontent.split('\n---\n', 1)
        fields, content = parts
        if len(parts) != 2:
            err_msg = 'gitcms.blog.load: expected "---" separator in file %s'
            raise IOError(err_msg % next)
        fields = yaml.load(fields)
        fields['content'] = preprocess_rst_content(content)
        categories = fields.get('categories', '')
        if 'categories' in fields:
            del fields['categories']
        ptags = []
        if categories:
            for c in categories.split():
                ptags.append(tag_for(c))
        P = BlogPost(**fields)
        P.save()
        for t in ptags:
            P.tags.add(t)
开发者ID:ReekenX,项目名称:django-gitcms,代码行数:39,代码来源:load.py


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