本文整理汇总了Python中models.Message.sent_at方法的典型用法代码示例。如果您正苦于以下问题:Python Message.sent_at方法的具体用法?Python Message.sent_at怎么用?Python Message.sent_at使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Message
的用法示例。
在下文中一共展示了Message.sent_at方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: conversation
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import sent_at [as 别名]
def conversation(sender_id, receiver_id):
"""
Show a conversation between two users.
"""
form = ConversationForm()
sender = User.query.filter_by(id=sender_id).first()
receiver = User.query.filter_by(id=receiver_id).first()
if not sender or not receiver:
return no_perms("One of the users provided does not exist!")
if sender.id != g.user.id:
receiver = sender
conv = Conversation.query.filter_by(
sender_id=sender_id
).filter_by(
receiver_id=receiver_id
).first() or \
Conversation.query.filter_by(
sender_id=receiver_id
).filter_by(
receiver_id=sender_id
).first()
if request.method == "POST":
if not conv:
if form.content.data and form.subject.data:
conv = Conversation(sender_id=sender_id,
receiver_id=receiver_id,
subject=form.subject.data)
db.session.add(conv)
db.session.commit()
msg = Message(conversation_id=conv.id,
sender=g.user.id,
content=form.content.data)
db.session.add(msg)
db.session.commit()
else:
return no_perms("You didn't input a subject or message!")
elif form.content.data:
msg = Message(conversation_id=conv.id,
sender=g.user.id,
content=form.content.data)
db.session.add(msg)
db.session.commit()
else:
return no_perms("You didn't input a message!")
if conv:
for msg in conv.messages:
msg.sent_at = msg.sent_at.strftime("%b %d, %Y")
conv.messages = Message.query.filter_by(conversation_id=conv.id).all()
return render_template("conversation.html", form=form, conversation=conv,
receiver=receiver)