flask-sqlalchemy

Speed: Store aggregate values in database or calculate with Jinja?

我是研究僧i 提交于 2019-12-11 03:24:23
问题 Language: Python Database: SQLite Using: Flask, SQLAlchemy ORM My question itself is probably an overkill, but I'm very curious. I have columns in an SQLAlchemy Table that hold certain values that I need to perform mathematical operations on, to display aggregate values or calculated values. Let's assume: Column 1 : 0 Column 2 : 5 Column 3 : 2 Column 4 : 6 In an HTML table, I need to rely on those values to calculate and display a result of an arithmetic operation on them. Example: ( Column 1

Flask-WhooshAlchemy with existing database

不问归期 提交于 2019-12-11 02:47:22
问题 How can I get Flask-WhooshAlchemy to create the .seg files for an already existing database filled with records? By calling: with app.app_context(): whooshalchemy.whoosh_index(app, MappedClass) I can get the .toc file, but the .seg files will only be created and once I insert a record directly via Flask-WhooshAlchemy interface. Thus all already existing records will never be included in a whoosh search. 回答1: Here is a script that indexes an existing database. FWIW, Whoosh refers to that as

why flask sqlalchemy model query does not get newest records?

我与影子孤独终老i 提交于 2019-12-11 02:32:42
问题 I have a Model class: class PlatformUsage(db.Model): __tablename__ = 'platform_usage' id = db.Column(db.BigInteger, primary_key=True) module = db.Column(db.String(64)) rb = db.Column(db.BigInteger) status = db.Column(db.String(64)) platform = db.Column(db.String(64)) def __init__(self, module, rb, status, platform): self.module = module self.rb = rb self.status = status self.platform = platform def __repr__(self): return "<PlatformUsage(module: %s, rb: %d, status: %s, platform: %s>" % ( self

SQLAlchemy Query with Multiple Joins

孤者浪人 提交于 2019-12-11 02:31:24
问题 I am creating a flask app with SQLAlchemy and Postgres. I am pretty green at this so I any feedback would be appreciated. However, my direct question is with constructing a query on the following model. from app import db from sqlalchemy import or_, and_ # Items Table class Item(db.Model): __tablename__ = "items" id = db.Column(db.Integer, primary_key=True) itemName = db.Column(db.String, unique=True, nullable=False) measurement = db.Column(db.String, nullable=False) defaultPrice = db.Column

SQLAlchemy: @property mapping?

非 Y 不嫁゛ 提交于 2019-12-11 02:26:10
问题 I have following models: class Details(db.Model): details_id = db.Column(db.Integer, primary_key=True) details_main = db.Column(db.String(50)) details_desc = db.Column(db.String(50)) class Data(db.Model): data_id = db.Column(db.Integer, primary_key=True) data_date = db.Column(db.Date) details_main = db.Column(db.String(50)) @property def details_desc(self): result = object_session(self).\ scalar( select([Details.details_desc]). where(Details.details_main == self.details_main) ) return result

Openshift app with flask, sqlalchemy and sqlite - problems with database reverting

大城市里の小女人 提交于 2019-12-11 01:37:11
问题 I have a problem pretty much exactly like this: How to preserve a SQLite database from being reverted after deploying to OpenShift? I don't understand his answer fully and clearly not enough to apply it to my own app and since I can't comment his answer (not enough rep) I figured I had to make ask my own question. Problem is that when pushing my local files (not including the database file) my database on openshift becomes the one I have locally (all changes made through the server are

Get app config from database entries

浪子不回头ぞ 提交于 2019-12-11 01:21:17
问题 I'm looking for a way to set some static app config value (as werkzeug server port) from database entries. My app uses SQLAlchemy and blueprints, and currently gets config from an object (config.py). Assuming the configuration for the database still comes from a config file, how can I configure the rest of the application from a database? 回答1: Read the key/value items from a table and set the config from those items. Keep in mind that the value column can only have one type (I've gone with

To use unicode or not in web development project using flask and sqlalchemy

ε祈祈猫儿з 提交于 2019-12-11 01:16:38
问题 I am working on a web development project using flask and sqlalchemy orm. My post is related to use of unicode in developing this app. What I have understood till now about unicode : If I want my webapp to handle data in languages other than English I need to use unicode data type for my variables. Because string variables can't handle unicode data. I use some database which stores unicode data or take responsibility to convert unicode to raw while saving and vice versa while retrieving.

sqlalchemy group_by gives error: column must appear in the GROUP BY clause or be used in an aggregate function

两盒软妹~` 提交于 2019-12-11 01:11:22
问题 Here's my query, simplified a little (some filters removed): q = Foo.query.\ join(Foo.bar).\ with_entities(Bar.BAZ, Foo.BAT, ...).\ group_by(Foo.BAT) This gives me an error: column "Bar.BAZ" must appear in the GROUP BY clause or be used in an aggregate function It seems like there are questions on stackoverflow dealing with this error already, like this one, but what they're trying to do is sufficiently dissimilar to what I'm trying to do that I'm having a hard time understanding how their

OperationalError: (OperationalError) no such column

我的未来我决定 提交于 2019-12-10 22:28:34
问题 I have a problem. I have to do this query: @app.route('/api/subscriptions/<string:id>', methods=('DELETE',)) @decorators.login_required def delete_subscription(id): dbsession = DBSession() session = Session() favorit = (dbsession.query(StudentsFavorites) .filter(Exams.number == str(id)) .filter(StudentsFavorites.exam_id) .filter(Students.id == StudentsFavorites.student_id) .filter(Students.id == str(session.get_user_id())) .delete() ) dbsession.flush() return jsonify(error=False) But when I