flask-sqlalchemy

Retrieving data from RDS gives AttributeError: 'sqlalchemy.cimmutabledict.immutabledict' object has no attribute 'setdefault'

為{幸葍}努か 提交于 2021-01-20 09:34:26
问题 I would like to retrieve user data from RDS whenever the API endpoint {{url}}/api/users/login is called to authenticate users, however, I am currently having issues with retrieving data from RDS. Error stacktrace This is the full stacktrace of the error: Current package versions Flask==1.1.2 Flask-Cors==3.0.10 flask-marshmallow==0.14.0 Flask-Migrate==2.5.3 Flask-RESTful==0.3.8 Flask-SQLAlchemy==2.4.4 marshmallow==3.10.0 marshmallow-sqlalchemy==0.24.1 SQLAlchemy==1.4.0b1 python==3.7 My

What's the difference between an association table and a regular table?

寵の児 提交于 2021-01-07 01:16:47
问题 I don't think I fully understand association tables. I know how to work with normal tables i.e add rows and what not but I don't understand how to work with an association table. why would I use the below student_identifier = db.Table('student_identifier', db.Column('class_id', db.Integer, db.ForeignKey('classes.class_id')), db.Column('user_id', db.Integer, db.ForeignKey('students.user_id')) ) Vs class studentIdent(db.model): db.Column(db.Integer, db.ForeignKey('classes.class_id')), db.Column

Unexpected argument warning on mixin with Python 3.6, Flask, and PyCharm

夙愿已清 提交于 2021-01-05 08:39:32
问题 I'm trying to implement a custom mixin in Python 3.6. Child classes would inherit its methods as well as base class. db = flask_sqlalchemy.SQLAlchemy() class CustomMixin(object): # {... __init__ is not being explicitly called, instance and class methods go here ...} class UserModel(CustomMixin, db.Model) # {... class variables, own and inherited methods go here ...} However, although my solution works, it gives a weak warning in PyCharm Community 2019.2: user = UserModel(class_var_1=value_1,

Flask SQLAlchemy query with concatenated columns

岁酱吖の 提交于 2021-01-04 05:31:29
问题 I have a models like this: class User(db.Model): id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(64), index=True) last_name = db.Column(db.String(64), index=True) def full_name(self): return '%s %s' % (self.first_name, self.last_name) I want to get the full_name method in a query, I try it like it: user = db.session.query(User.full_name()).all() But I get this error message: TypeError: full_name() missing 1 required positional argument: 'self' Then I try to call

Using proper file structure with SQLAlchemy and how to add data to db

感情迁移 提交于 2020-12-31 06:51:06
问题 I am trying to build a simple blogging platform to learn Python and Flask. I am using SQLAlchemy to connect to a Postgres db hosted on Heroku and flask_s3 to serve static files from an AWS bucket. Im mostly following along from this: https://gist.github.com/mayukh18/2223bc8fc152631205abd7cbf1efdd41/ All was going well, it is correctly hosted on Heroku and connceted to AWS S3 bucket, ready to go. I am stuck however on how to add blog posts to the database through some kind of form or route

Using proper file structure with SQLAlchemy and how to add data to db

浪尽此生 提交于 2020-12-31 06:49:12
问题 I am trying to build a simple blogging platform to learn Python and Flask. I am using SQLAlchemy to connect to a Postgres db hosted on Heroku and flask_s3 to serve static files from an AWS bucket. Im mostly following along from this: https://gist.github.com/mayukh18/2223bc8fc152631205abd7cbf1efdd41/ All was going well, it is correctly hosted on Heroku and connceted to AWS S3 bucket, ready to go. I am stuck however on how to add blog posts to the database through some kind of form or route

Using proper file structure with SQLAlchemy and how to add data to db

老子叫甜甜 提交于 2020-12-31 06:48:30
问题 I am trying to build a simple blogging platform to learn Python and Flask. I am using SQLAlchemy to connect to a Postgres db hosted on Heroku and flask_s3 to serve static files from an AWS bucket. Im mostly following along from this: https://gist.github.com/mayukh18/2223bc8fc152631205abd7cbf1efdd41/ All was going well, it is correctly hosted on Heroku and connceted to AWS S3 bucket, ready to go. I am stuck however on how to add blog posts to the database through some kind of form or route

Using proper file structure with SQLAlchemy and how to add data to db

不打扰是莪最后的温柔 提交于 2020-12-31 06:46:26
问题 I am trying to build a simple blogging platform to learn Python and Flask. I am using SQLAlchemy to connect to a Postgres db hosted on Heroku and flask_s3 to serve static files from an AWS bucket. Im mostly following along from this: https://gist.github.com/mayukh18/2223bc8fc152631205abd7cbf1efdd41/ All was going well, it is correctly hosted on Heroku and connceted to AWS S3 bucket, ready to go. I am stuck however on how to add blog posts to the database through some kind of form or route

SQLAlchemy filter on list attribute

て烟熏妆下的殇ゞ 提交于 2020-12-31 05:52:21
问题 I have the following model defined with Flask-SQLAlchemy: """models.py""" from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() skill_candidate = db.Table( 'SkillCandidate', db.Column('skill_id', db.String, db.ForeignKey('skill.id')), db.Column('candidate_id', db.Integer, db.ForeignKey('candidate.id'))) class Candidate(db.Model): id = db.Column(db.Integer, primary_key=True) skills = db.relationship("Skill", secondary=skill_candidate) class Skill(db.Model): id = db.Column(db.String,

flask sqlalchemy many to many relationship with extra field

流过昼夜 提交于 2020-12-29 09:11:57
问题 I have 2 tables: restaurants and foods, and a 3rd table restaurants_foods which stores the many to many relationship between the 2 tables restaurants_foods = db.Table('restaurants_foods', db.Column('restaurant_id', db.Integer, db.ForeignKey('restaurants.id'), primary_key=True), db.Column('food_id', db.Integer, db.ForeignKey('foods.id'), primary_key=True), db.Column('food_price', db.Float) ) class Food(Model): __tablename__ = "foods" id = db.Column(db.Integer, primary_key=True, autoincrement