A picture is worth a thousand words. Here’s what I’m trying to fix in Flask-Admin: I’m trying to edit a field from the list view by including the field in the column_editable_list of the model view. The field’s values come from another table via a foreign key relationship, so the user selects a value from the dropdown menu, which is
Tag: flask-sqlalchemy
Flask SQLAlchemy reflection ignoring most of tables on Redshift
I’m creating the engine and the Metadata as follows Yields AttributeError: packages, and dir(Base.classes) returns no attributes with that name, neither with the orders name. Taking the only=[‘orders’, ‘packages’] off makes it reflect only a few random tables. Now, when using the inspector that comes with native SQLAlchemy the table actually works (link to documentation): Is this a bug, or
AttributeError: module ‘time’ has no attribute ‘clock’ In SQLAlchemy python 3.8.2
Answer The error occurs because in python 2, there is time.clock(), but in python 3, it has been replaced with time.perf_counter(). Just replace all the time.clock to time.perf_counter, and it should be fine. For more info: https://www.webucator.com/blog/2015/08/python-clocks-explained/
Can I have 2 user_loader methods in my Flask web application
In my web application users and workers can login and I have 2 different models for them. However, when I try to create a user_loader method for the worker model I receive and error Here is my code Answer @login_manager.user_loader is a decorator present in the login_manager class – it does not represent different types of users (i.e. user and
How to accept None for String type field when using Flask-RESTPlus
I am just starting develop with flask-restplus and I am not a native speaker, but I will try to describe my question as clear as I can. I know there is a fields module in flask that help us define and filter response data type, such as String, Integer, List and so on. Is there any way to allow NULL
How to filter and display flask sqlalchemy one to many relationship data with jinja
I have two mysql tables (“song_info” and “djartist1”) which they have one to many relationship. I want to display the all songs from a single artist (all posts from a specific user). But I’m getting a list, instead of what I want to be displayed on the html file. Can you give me a solution please ?. here are the
sqlalchemy foreign key could not find table
I’m making a database using sqlalchemy which consists of three classes, User, Meeting, MeetingRoom I want to create a foreign key in Meeting for the Meeting room, but for some reason it gives the following error sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column ‘meeting.mrid’ could not find table ‘meetingroom’ with which to generate a foreign key to target column ‘mrid’ When
how flask-sqlalchemy turn off returning id while insert data
I’m trying to insert data to PostgreSQL 8.3.23 by Flask-SQLAlchemy==2.3.2, the errors show that INSERT statement is not supported in this version of Greenplum Database. so how can I turn off returning id in (flask-)sqlalchemy while insert. Thanks in advance Answer You need to set the implicit_returning create_engine parameter to False. When True, a RETURNING- compatible construct, if available, will
How to skip records in SqlAlchemy query?
I have 100 rows in my DB. I’m trying to execute select query but I want to skip the first 10 rows (i.e. I want rows in range 11-20). How can I do this? Answer The raw SQL is like: In SqlAlchemy language it’s like:
Create a Full Text Search index with SQLAlchemy on PostgreSQL
I need to create a PostgreSQL Full Text Search index in Python with SQLAlchemy. Here’s what I want in SQL: Now how do I do the second part with SQLAlchemy when using the ORM: Answer You could create index using Index in __table_args__. Also I use a function to create ts_vector to make it more tidy and reusable if more