flask-sqlalchemy

SQLAlchemy session.execute() return value CursorResult , return row as dict

SQLAlchemy session.execute() return value CursorResult , return row as dict Question: I am currently using sqlalchemy 1.4.2 I am using session.execute(statement) to fetch rows from my Db table. This is the code I have used below: query = f"SELECT * FROM mytable WHERE entity_guid IN {entity_guids}" results = session.execute(query) for result in results: print(results) final.append({**result}) …

Total answers: 1

Update a value based on Join FlaskSqlALchemy

Update a value based on Join FlaskSqlALchemy Question: I have 2 tables in db. class Vehicle(db.Model): __tablename__ = "vehicles" id = db.Column(db.Integer, primary_key=True, nullable=False) num_plate = db.Column(db.String(7), nullable=False, unique=True) type = db.Column(db.String, nullable=False) suspicious = db.Column(db.Boolean, nullable=False, default=False) def __repr__(self) -> str: return f"Vehicle(number playe={self.num_plate}, type={self.type}, suspicious={self.suspicious})" class Registered(db.Model): """ Registered User """ __tablename__ = …

Total answers: 2

Changing Date format with default property

Changing Date format with default property Question: 0 `vectorizer = TfidfVectorizer(analyzer=’word’,norm=None, use_idf=True,smooth_idf=True) tfIdfMat = vectorizer.fit_transform(df[‘Description’]) feature_names = sorted(vectorizer.get_feature_names()) docList=[‘df.Description’] #skDocsTfIdfdf = pd.DataFrame(tfIdfMat.todense(),index=sorted(docList), columns=feature_names) #print(skDocsTfIdfdf) for col in tfIdfMat.nonzero()[1]: print (feature_names[col], ‘-‘ , tfIdfMat[0, col])` Asked By: Mr xyz || Source Answers: I think you can encapsulate a function, return the time in this format, and …

Total answers: 1

Factory boy to select from existing flask_sqlalchemy table with Iterator using parameter

Factory boy to select from existing flask_sqlalchemy table with Iterator using parameter Question: There are lots of great answers here, but I can’t quite find the one to solve my problem. Two SQLAlchemy models: Calendar and Transaction. Transactions link to the Calendar model: class Calendar(Model): calendar_id = db.Column(db.Integer, primary_key=True, autoincrement=True) cal_date = db.Column(db.Date, unique=True, nullable=False) …

Total answers: 1

Exact match with filter() Flask

Exact match with filter() Flask Question: I’am new to python and iam coding a small webapp to search in a database. Its fonctionnal but doesnt function well. Example : If i search for a ‘lieu’, a ‘Annee’ and a ‘Signataire’ it doesnt give me the exact matches, instead it gives me every ‘Signataire’ even if …

Total answers: 2

How to avoid the QueuePool limit error using Flask-SQLAlchemy?

How to avoid the QueuePool limit error using Flask-SQLAlchemy? Question: I’m developing a webapp using Flask-SQLAlchemy and a Postgre DB, then I have this dropdown list in my webpage which is populated from a select to the DB, after selecting different values for a couple of times I get the "sqlalchemy.exc.TimeoutError:". My package’s versions are: …

Total answers: 3

Skip the default on onupdate defined, for specific update queries in SQLAlchemy

Skip the default on onupdate defined, for specific update queries in SQLAlchemy Question: If I have a list of posts, which have created and updated dates with a default attached onupdate callback. Sometimes I need to flag the post, for inappropriate reports or similar actions. I do not want the created and updated dates to …

Total answers: 2

VSCODE doesn't recognize subclassing of db.Model

VSCODE doesn't recognize subclassing of db.Model Question: I have a Flask Project with Flask-SQLAlchemy and a custom Model class. For type hinting I modified the SQLAlchemy class like this: class CustomSQLAlchemy(flask_sqlalchemy.SQLAlchemy): Model: CustomModel After that, VSCODE does show db.Model as a CustomModel: However, when adding attributes I don’t get any suggestions for attributes from db.Model …

Total answers: 2

AttributeError: can't set attribute when connecting to sqlite database with flask-sqlalchemy

AttributeError: can't set attribute when connecting to sqlite database with flask-sqlalchemy Question: I’ve been learning the flask web application framework and feel quite comfortable with it. I’ve previously built a simple to do app that worked perfectly. I was working on the same project, but trying to implement it using TDD. I’ve encountered an error …

Total answers: 6

flask-sqlalchemy query for returning newest and using distinct columns

flask-sqlalchemy query for returning newest and using distinct columns Question: I am really struggling to write the correct postgres query that I want in flask-sqlalchemy. A sample table of what my data looks like is below. I am trying to get back xxx and yyy for the newest (latest time stamp) for each unique name. …

Total answers: 2