flask-sqlalchemy

Flask: are blueprints necessary for app factories?

限于喜欢 提交于 2019-12-03 02:44:32
I want to have several app factories(currently: one for development, and another one for testing). I am wondering what is the proper way to implement them. Currently I use app object to register views(via @app.route() decorator). Do I need to start using blueprints(instead of app) to register views? Is there any way to have proper app factories without blueprients? technically, you don't need blueprints, you can just register each route on your create_app function. Generally speaking that's not a great idea, and it's kind of why blueprints exist. Example without blueprints def create_app():

alembic util command error can't find identifier

[亡魂溺海] 提交于 2019-12-03 02:39:00
问题 I'm trying to use alembic to handle local migrations on my project. It worked the first time, but then I needed to delete the folder and restart.(don't ask why, I just had to) I'm following this tutorial and I run the command python manage.py db init And it was ok. But when I try to run python manage.py db migrate I'm getting this error: alembic.util.CommandError: Can't locate revision identified by '31b8ab83c7d' Now, it seems that alembic is looking for a revision that doesn't exists anymore

How to specify table relationships in SQLAlchemy with multi-level/multiple joins?

£可爱£侵袭症+ 提交于 2019-12-03 02:25:42
I'm trying to define a relationship between two tables whose relations are indirect (i.e. through two other tables). The results I'm looking for can be fetched with this query: (db.session.query(Telnum) .filter(Account.customer==customer) .filter(Account.account_id == Subscription.account_id) .filter(Telnum.sub_id == Subscription.id) .order_by(Telnum.telnum) .all() ) where customer is a Customer object. I'm struggling to figure out how this would be defined as a relationship, similar to the Customer.invoices relationship. An idea I had was something like this: telnums = db.relationship('Telnum

Pylint can't find SQLAlchemy query member

老子叫甜甜 提交于 2019-12-03 02:12:45
问题 I have a Flask (v0.10.1) application using Flask-SQLAlchemy (v2.0) and I'm trying to configure Pylint to check it. Running with Python 3.4.2. First error was: Instance of 'SQLAlchemy' has no 'Table' member (no-member) And I fixed this one ignoring the check for member attributes on SQLAlchemy: ignored-classes=SQLAlchemy But I'm having a problem with the query member on entities: Class 'UserToken' has no 'query' member (no-member) Is there any way to fix this issue without having to ignore no

What is wrong with my relationships in SQL Alchemy?

£可爱£侵袭症+ 提交于 2019-12-03 01:59:15
I am using SQLAlchemy with Flask to create relationships for my application. I recently rewrote the relationships, and, no matter what I change, I keep getting the error: sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between parent/child tables on relationship CurriculumVersion.enrollments - there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression. On my models: class User(db.Model, AuthUser): id = db.Column(db.Integer, primary_key=True) tf_login = db

Pythonic way to correctly separate Model from application using SQLAlchemy

空扰寡人 提交于 2019-12-03 01:06:43
问题 I'm having a hard time to make my application run. Flask-SQLAlchemy extension creates an empty database whenever I try to separate module in packages. To better explain what I'm doing, let me show how my project is structured: Project | |-- Model | |-- __init__.py | |-- User.py | |-- Server | |-- __init__.py | |-- API | |-- __init__.py The idea is simple: I want to create a package for my model, as I don't like spreading code in a single package, and separate "sub" projects (like API), as in

sqlalchemy, select using reverse-inclusive (not in) list of child column values

社会主义新天地 提交于 2019-12-02 22:29:36
I have a typical Post / Tags (many tags associated with one post) relationship in flask-sqlalchemy, and I want to select posts which aren't tagged with any tag in a list I provide. First, the models I set up: class Post(db.Model): id = db.Column(db.Integer, primary_key=True) tags = db.relationship('Tag', lazy='dynamic') class Tag(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Text(50)) post_id = db.Column(db.Integer, db.ForeignKey('post.id')) Something like db.session.query(Post).filter(Post.tags.name.notin_(['dont','want','these'])) fails with AttributeError:

Render Jinja after jQuery AJAX request to Flask

≡放荡痞女 提交于 2019-12-02 21:22:15
I have a web application that gets dynamic data from Flask when a select element from HTML is changed. of course that is done via jquery ajax . No probs here I got that. The problem is, the dynamic data - that is sent by Flask - , is a list of objects from the database Flask-sqlalchemy . Of course the data is sent as JSON from Flask . I'd like to iterate through those objects to display their info using Jinja . HTML <select id="#mySelect"> <option value="option1" id="1">Option 1 </option> <option value="option2" id="1">Option 2 </option> <option value="option3" id="3">Option 3 </option> <

Configuring Flask-SQLAlchemy to use multiple databases with Flask-Restless

泄露秘密 提交于 2019-12-02 20:58:13
I have a Flask app that uses Flask-SQLAlchemy and I'm trying to configure it to use multiple databases with the Flask-Restless package. According to the docs , configuring your models to use multiple databases with __bind_key__ seems pretty straightforward. However it doesn't seem to be working for me. I create my app and initialise my database like this: from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy SQLALCHEMY_DATABASE_URI = 'postgres://db_user:db_pw@localhost:5432/db_name' SQLALCHEMY_BINDS = { 'db1': SQLALCHEMY_DATABASE_URI, 'db2': 'mysql://db_user:db_pw@localhost:3306

flask-sqlalchemy - PostgreSQL - Define specific schema for table?

我与影子孤独终老i 提交于 2019-12-02 20:33:05
I want to define a specific schema for a 'model' using flask-sqlalchemy. When you create a table object in sqlalchemy itself it has a parameter to pass for schema name. How do I do this in flask-sqlalchemy? When you define your model class use: __table_args__ = {"schema":"schema_name"} maybe it will save someone else some hunting. For future references: db = flask.ext.sqlalchemy.SQLAlchemy(app) app.config['SQLALCHEMY_DATABASE_URI'] = 'your_default_schema_db_uri' app.config['SQLALCHEMY_BINDS'] = {'other_schema': 'your_other_db_uri'} class TableA(db.Model): # This belongs to Default schema, it