Answer the question
In order to leave comments, you need to log in
How to update custom fields of the Sessions model in Flask?
Good afternoon!
I'm trying to learn Flask. Out of the box, the documentation is intelligible and understandable, but I needed to store in the database in the sessions table, in addition to the regular data for flask_sessions, several of my own fields.
Here is the model I created:
class Sessions(db.Model):
__table_args__ = { 'extend_existing': True }
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable = True)
room_id = db.Column(db.Integer, db.ForeignKey('room.id'), nullable = True)
print(app.session_interface.sql_session_model.id)
Sessions.id
session.user_id = 1
session.commit()
row = db.session.query(Sessions).filter_by(session_id = 'session:%s'%session.sid).first()
row.user_id = 1
db.session.commit()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question