本文整理汇总了Python中blog.models.Blog.published_date方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.published_date方法的具体用法?Python Blog.published_date怎么用?Python Blog.published_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Blog
的用法示例。
在下文中一共展示了Blog.published_date方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_blog
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import published_date [as 别名]
def edit_blog(request, username, blog_id=None):
if request.method == "POST":
if blog_id is None:
blog = Blog()
blog.create_date = datetime.now()
blog.username = username
else:
blog = Blog.objects.get(pk=blog_id)
form = BlogForm(request.POST, instance=blog)
if form.is_valid():
blog.modify_date = datetime.now() # every edit changed the modify date
blog.published_date = (
None
) # since we have edited the blog we will need to re-publish it (maybe not the right thing to do)
# import logging; logging.debug(form.instance.__dict__)
form.save()
# import logging; logging.debug(form.instance.__dict__)
return redirect("blog.views.view_blog", username=username, blog_id=blog.pk)
else:
if blog_id is None:
form = BlogForm()
else:
blog = get_object_or_404(Blog, pk=blog_id)
form = BlogForm(instance=blog)
return render_to_response(
"blog/edit_blog.html",
{"blog_id": blog_id, "form": form, "username": username},
context_instance=RequestContext(request),
)