flask-sqlalchemy

Flask / SQL Alchemy raw query instead of class method

别来无恙 提交于 2020-06-13 12:12:05
问题 I'll acknowledge that this is a strange question before I ask it. I'm wondering if it's possible to replicate Flask / SQL Alchemy class methods using raw SQL instead of using the methods themselves? Long story short, my teammates and I are taking a database design course, and we're now in the implementation phase where we are coding the app that is based on our DB schema design. We want to keep things simple, so we opted for using Flask in Python. We're following the Flask Mega Tutorial,

Storing a PDF file in DB with Flask-admin

无人久伴 提交于 2020-06-09 15:22:14
问题 can I store PDF files in the database, as object or blob, with Flask-Admin? I do not find any reference in the documentation. Thanks. Cheers 回答1: Below is a self contained an example of storing files directly in a blob field via Flask-Admin. There is minimal error checking but it should get you going in the right direction. The important parts of the code: class BlobMixin(object): mimetype = db.Column(db.Unicode(length=255), nullable=False) filename = db.Column(db.Unicode(length=255),

Storing a PDF file in DB with Flask-admin

两盒软妹~` 提交于 2020-06-09 15:20:29
问题 can I store PDF files in the database, as object or blob, with Flask-Admin? I do not find any reference in the documentation. Thanks. Cheers 回答1: Below is a self contained an example of storing files directly in a blob field via Flask-Admin. There is minimal error checking but it should get you going in the right direction. The important parts of the code: class BlobMixin(object): mimetype = db.Column(db.Unicode(length=255), nullable=False) filename = db.Column(db.Unicode(length=255),

Associate "external' class model with flask sqlalchemy

雨燕双飞 提交于 2020-06-09 08:55:49
问题 We use a central class model for a wide variety of python modules. This model is defined using SQLAlchemy. The classes all inherit from declarative_base. For example, our model definitions look something like this: Base = declarative_base() class Post(Base): __tablename__ = 'Posts' id = Column(INT, primary_key=True, autoincrement=True) body = Column(TEXT) timestamp = Column(TIMESTAMP) user_id = Column(INT, ForeignKey('Users.uid')) We have been building a flask web-application in which we

Associate "external' class model with flask sqlalchemy

醉酒当歌 提交于 2020-06-09 08:55:10
问题 We use a central class model for a wide variety of python modules. This model is defined using SQLAlchemy. The classes all inherit from declarative_base. For example, our model definitions look something like this: Base = declarative_base() class Post(Base): __tablename__ = 'Posts' id = Column(INT, primary_key=True, autoincrement=True) body = Column(TEXT) timestamp = Column(TIMESTAMP) user_id = Column(INT, ForeignKey('Users.uid')) We have been building a flask web-application in which we

Associate "external' class model with flask sqlalchemy

烈酒焚心 提交于 2020-06-09 08:54:06
问题 We use a central class model for a wide variety of python modules. This model is defined using SQLAlchemy. The classes all inherit from declarative_base. For example, our model definitions look something like this: Base = declarative_base() class Post(Base): __tablename__ = 'Posts' id = Column(INT, primary_key=True, autoincrement=True) body = Column(TEXT) timestamp = Column(TIMESTAMP) user_id = Column(INT, ForeignKey('Users.uid')) We have been building a flask web-application in which we

How to get the list of users who are currently logged in Flask-Login?

妖精的绣舞 提交于 2020-06-09 05:27:28
问题 In my Flask-SQLAlchemy web application I have implemented Flask-Login for user authentication and authorization. Now I am building an Admin section where the admin user can add, edit or delete any user and view user list. So before deleting any user I want to know whether that user is currently logged in to the application from somewhere or simply having any active session with the web application. How can I accomplice this? Or Is this even possible in the application level? [ Note: As you

flask_sqlalchemy object does not have attribute add when using flask_security

人走茶凉 提交于 2020-05-28 07:45:16
问题 I am trying to add some roles/users with flask_security but run into this issue when I try to create users with the SQLAlchemySessionUserDatastore . So I first start by creating user_datastore like the guide db = SQLAlchemy(app) user_datastore = SQLAlchemySessionUserDatastore(db, User, Role) security = Security(app, user_datastore) user_datastore.create_user(email='test', password='passowrd') this is where I deviate from the guide and try to just create a test user. Looks like the db =

flask_sqlalchemy object does not have attribute add when using flask_security

孤人 提交于 2020-05-28 07:44:29
问题 I am trying to add some roles/users with flask_security but run into this issue when I try to create users with the SQLAlchemySessionUserDatastore . So I first start by creating user_datastore like the guide db = SQLAlchemy(app) user_datastore = SQLAlchemySessionUserDatastore(db, User, Role) security = Security(app, user_datastore) user_datastore.create_user(email='test', password='passowrd') this is where I deviate from the guide and try to just create a test user. Looks like the db =

flask_sqlalchemy object does not have attribute add when using flask_security

别说谁变了你拦得住时间么 提交于 2020-05-28 07:44:06
问题 I am trying to add some roles/users with flask_security but run into this issue when I try to create users with the SQLAlchemySessionUserDatastore . So I first start by creating user_datastore like the guide db = SQLAlchemy(app) user_datastore = SQLAlchemySessionUserDatastore(db, User, Role) security = Security(app, user_datastore) user_datastore.create_user(email='test', password='passowrd') this is where I deviate from the guide and try to just create a test user. Looks like the db =