本文整理汇总了Python中blog.models.Article.post_date方法的典型用法代码示例。如果您正苦于以下问题:Python Article.post_date方法的具体用法?Python Article.post_date怎么用?Python Article.post_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Article
的用法示例。
在下文中一共展示了Article.post_date方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: article_create
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import post_date [as 别名]
def article_create():
form = ArticleCreateForm()
form.category_id.choices = Category.choices()
if request.method == 'POST' and form.validate():
if not g.user.is_admin():
flash(u'非管理员不能创建文章!')
return redirect(url_for('index'))
else:
nowtime = datetime.datetime.now()
article = Article(title=form.title.data,
body=form.body.data,
user_id=g.user.id,
category_id=form.category_id.data,
text=request.form.get('textformat'),
timestamp=nowtime,
tag=form.tag.data,
is_open=form.is_open.data)
article.post_date = nowtime
db.session.add(article)
db.session.commit()
flash(u'文章已创建!')
Blog_info.new_article()
return redirect(url_for('article_edit', id=article.id))
return render_template('article_create.html',
title=u'创建文章',
form=form)
示例2: article_commit
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import post_date [as 别名]
def article_commit():
if g.user.is_admin():
data = request.form
title, category, tag, is_open, body, text, art_id = data['title'], data['category'], data['tag'], \
data['open'], data['body'], data['text'], data["id"]
if title == '' or tag == '' or body == '' or text == '':
return json.dumps({'msg': u'必填字段不能为空'})
if art_id:
article = Article.find_by_id(int(id))
article.title = title
article.category_id = category
article.tag = tag
article.is_open = is_open
article.body = body
article.text = text
article.timestamp = datetime.datetime.now()
db.session.add(article)
else:
nowtime = datetime.datetime.now()
article = Article(title=title,
body=body,
user_id=g.user.id,
category_id=category,
text=text,
timestamp=nowtime,
tag=tag,
is_open=is_open)
article.post_date = nowtime
try:
db.session.add(article)
db.session.commit()
return json.dumps({'msg': u'保存成功'})
except:
return json.dumps({'msg': u'保存失败'})
else:
return json.dumps({'msg': u'请用管理员账号登陆'})