コード例 #1
0
def add_message():
    data = request.get_json(silent=True)
    db_sess = create_session()
    message = Messages()
    message.chatId = data["chatId"]
    message.authorId = current_user.id
    message.content = data["content"]
    db_sess.add(message)
    db_sess.commit()
    return {}
コード例 #2
0
def about(id):
    form = MessageForm()
    db_sess = db_session.create_session()
    question = db_sess.query(Questions).filter(Questions.id == id).first()
    messages = db_sess.query(Messages).filter(Messages.question_id == id)
    if form.validate_on_submit():
        message = Messages()
        message.content = form.content.data
        message.question_id = db_sess.query(Questions).filter(
            Questions.id == id).first().id
        message.user_id = current_user.id
        message.creation_date = datetime.datetime.now().replace(microsecond=0)
        db_sess.merge(message)
        db_sess.commit()
        return redirect(f'/{id}')
    db_sess.commit()
    return render_template('about.html',
                           question=question,
                           messages=messages,
                           form=form)