flask-sqlalchemy

SQLAchemy 'No application found. Either work inside a view function or push'

旧时模样 提交于 2019-12-11 18:28:21
问题 Ello ello, I found similar questions on the bug i'm facing, and tried the solutions offered but it didn't work for me. I'm trying to separate out my models in a different directory and import them into the app.py When I try to import the db into the python terminal, i'm getting the no application found. app.py code from flask import Flask from flask_restful import Resource, Api # from flask_sqlalchemy import SQLAlchemy from routes import test, root, user from models.todo import db app = Flask

Flask, SQLAlchemy cannot retrieve data from db, and send it in GET request

和自甴很熟 提交于 2019-12-11 17:05:54
问题 I''m still new to Flask/SQLAlchemy. I made this where I was having context issues. I've managed to fixed the SQLAlchemey issue, but now I am unable to retrieve data from my postgres DB I have a separate directory for models, routes and a main app.py file. I'm initializing my db in app.py, importing the db in models.model and creating a basic class. I've managed to add data manually in python terminal and by hard coding a new class in the app.py file. I see this table/data in postgres. The

Is there a reverse function of .in_ in SQLAlchemy?

随声附和 提交于 2019-12-11 17:05:51
问题 I'm trying to organize my blog posts by "tags", which is just a string of words separated by commas. I want to be able to select a tag which would only show posts that have that tag somewhere in the string of tags. For example: Post1 - tags: "world politics, technology" Post2 -tags: "technology" Selecting "world politics" - I only want Post1. Selecting "technology" I want Post1 and Post2. I'm trying to use the .in_ filter function, but as of right now it won't select anything @app.route('

SQLAlchemy with multiple Many to Many Relationships

元气小坏坏 提交于 2019-12-11 16:52:00
问题 I would like create a database for recipes with SQLAlchemy, however I am not sure if my approach is correct. How can I insert data to the recipe_ingredient table? My approach: A recipe has a name and can have multiple ingredients. One ingredient consists of an amount, an unit and a name (ingredients table), for example 500 ml water. Table recipe - id, primary key - name (one recipe can have multiple ingredients and one ingredient can be in multiple recipes) table recipe_ingredient foreignkey

One-to-one relationship in Flask

牧云@^-^@ 提交于 2019-12-11 16:51:42
问题 I'm trying to create a one-to-one relationship in Flask using SqlAlchemy. I followed this previous post and I created the classes like ones below: class Image(db.Model): __tablename__ = 'image' image_id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(8)) class Blindmap(db.Model): __tablename__ = 'blindmap' module_id = db.Column(db.Integer, primary_key = True) image_id = db.Column(db.Integer, ForeignKey('image.image_id')) Although it can migrate the model to the sqlite3

Overriding the table name in Flask-Alchemy

▼魔方 西西 提交于 2019-12-11 14:58:18
问题 I am creating a Flask application and accessing the MySQL database using Flask-Alchemy. I have following Class to access a table: class price_table(db.Model): id = db.Column(db.Integer, primary_key = True) trans_id = db.Column(db.Integer) timestamp = db.Column(db.Integer) order_type = db.Column(db.String(25)) price = db.Column(db.Numeric(15,8)) quantity = db.Column(db.Numeric(25,8)) def __repr__(self): return 'id' For the table 'price_table' this works brilliantly, but problem is I have a few

Error when aquiring date time data on Flask app

白昼怎懂夜的黑 提交于 2019-12-11 14:29:00
问题 Background What I would like to do is to implement a form to insert datetime with the specific data type (like 2019-10-23 22:38:18) on a web application written in Python Flask and SQLAlchemy. my former question: Inappropriate datetime datatype and error on Flask App Problem and Error message When I edit @app.route('/') def index(): return render_template('index.html', data=Todo.query.all(), form=form) It returned the error "NameError: name 'form' is not defined" But, when I get rid of form

How to show all users including my friends using SQLAlchemy

扶醉桌前 提交于 2019-12-11 14:24:35
问题 I am trying to show a list of all users including my friends. Database : relationships table: Users table : Server side : q1 = db.session.query(User).add_columns(User.id,User.name,Relationship.status).join( Relationship, User.id == Relationship.user1_Id).filter(Relationship.user2_Id == id) q2 = db.session.query(User).add_columns(User.id,User.name,Relationship.status).join( Relationship, User.id == Relationship.user2_Id).filter(Relationship.user1_Id == id) q3 = db.session.query(User).add

How to perform a natural join on two tables using SQLAlchemy and Flask?

∥☆過路亽.° 提交于 2019-12-11 13:52:46
问题 I have two tables Entry and Group defined in Python using Flask SQLAlchemy connected to a PostgresSQL database: class Entry (db.Model): __tablename__ = "entry" id = db.Column('id', db.Integer, primary_key = True) group_title = db.Column('group_title', db.Unicode, db.ForeignKey('group.group_title')) url = db.Column('url', db.Unicode) next_entry_id = db.Column('next_entry_id', db.Integer, db.ForeignKey('entry.id')) entry = db.relationship('Entry', foreign_keys=next_entry_id) group = db

sqlalchemy symmetric many to one friendship

萝らか妹 提交于 2019-12-11 12:14:11
问题 I am attempting to model a friendship using SQLAlchemy ORM. The relationship that I am trying to model is symmetric. Similar to Facebook, if user a is to add user b, user b must approve that friendship request. My current model is as follows. class User(db.Model): __tablename__ = 'User' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(35), unique=False) username = db.Column(db.String(25), index=True, unique=True) password = db.Column(db.String(35), unique=False) email =