本文整理汇总了Python中models.Topic.parent_topic方法的典型用法代码示例。如果您正苦于以下问题:Python Topic.parent_topic方法的具体用法?Python Topic.parent_topic怎么用?Python Topic.parent_topic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Topic
的用法示例。
在下文中一共展示了Topic.parent_topic方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_topic
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import parent_topic [as 别名]
def create_topic():
title = start = end = parent_topic_key = ''
message = None
if request.method == 'POST':
title = request.form.get('title')
if not title:
flash('Title required.', 'error')
else:
topic = Topic(title=title, author=g.user)
parent_topic_key = request.form.get('parent_topic_key')
parent_topic = None
if parent_topic_key:
parent_topic = Topic.get(parent_topic_key)
topic.parent_topic = parent_topic
start = request.form.get('start')
if start:
try:
start = datetime.strptime(start, '%Y-%m-%d %H:%M')
except ValueError:
start = datetime.now()
topic.start = start
end = request.form.get('end')
if end:
try:
end = datetime.strptime(end, '%Y-%m-%d %H:%M')
topic.end = end
except ValueError:
pass
new_topic_key = topic.put()
if parent_topic:
parent_topic.child_topics.append(new_topic_key)
parent_topic.put()
flash('Topic "%s" created.!' % title)
return redirect(url_for('discussion', topic_key=new_topic_key))
elif request.method == 'GET':
message_key = request.args.get('message_key')
if message_key:
message = Message.get(message_key)
parent_topic_key = str(message.topic.key())
start = datetime.now().strftime('%Y-%m-%d %H:%M')
title = 'On - %s' % message.content
return render_template('index.html', title=title, start=start, end=end,
parent_topic_key=parent_topic_key, message=message)