flask-sqlalchemy

sqlalchemy filter by json field

独自空忆成欢 提交于 2020-07-04 07:55:00
问题 I have model with json column . Example of model and data: app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres://...' db = SQLAlchemy() db.init_app(app) app.app_context().push() class Example(db.Model): id = db.Column(db.Integer(), nullable=False, primary_key=True, ) json_field = db.Column(db.JSON()) db.create_all() db.session.add(Example(json_field={'id': None})) db.session.add(Example(json_field={'id': 1})) db.session.add(Example(json_field={'id': 50})) db.session.add

sqlalchemy filter by json field

Deadly 提交于 2020-07-04 07:54:46
问题 I have model with json column . Example of model and data: app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres://...' db = SQLAlchemy() db.init_app(app) app.app_context().push() class Example(db.Model): id = db.Column(db.Integer(), nullable=False, primary_key=True, ) json_field = db.Column(db.JSON()) db.create_all() db.session.add(Example(json_field={'id': None})) db.session.add(Example(json_field={'id': 1})) db.session.add(Example(json_field={'id': 50})) db.session.add

How can I get the blog_id of the rows of the sqlite table I just query and used? (In a Python file)

不打扰是莪最后的温柔 提交于 2020-07-03 09:28:05
问题 I have the codes below that let users on my website to search for blogs. With the current, my HTML page will only show a list of data from all the row that has columns that match with the search input. But, I want to get the blog_id of all the matching rows that I just query with c.fetchall(). How would I do it? Should I write some codes right after I query data?... I would greatly appreciate if you help me. Also, if possible, could you show me how can I set the codes below to only query

How to loop through related tables with Jinja2?

☆樱花仙子☆ 提交于 2020-06-29 06:39:29
问题 Description I am learning Flask and I created a database which contains 3 tables which are related between them: Company: info about the company I worked for (made up :) ) Job: info about the role I had in each company Task: info about the tasks i had in each job i had in each company. Here is the code: from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy from datetime import datetime app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///work

get all employees whose job code in a list

独自空忆成欢 提交于 2020-06-29 03:59:26
问题 I am developing a web application by python Flask, uses flaskSqlalchemy with PostgreSQL. we have a search functionality where user enter first name, last name, language known. for eg, if the user enters the language as java, it will return a list of empid, with this empid we need to get his full name. my flasksqlalchemy implementation is langCode = EmpProf().getLancodes(lang) in EmpProf class def getLancodes(lang): return EmpProf.query.distinct(EmpProf.langCod).filter(EmpProf.langKn.ilike('%'

Unable to insert data into Mysql Using FLASK+SQLALCHEMY

霸气de小男生 提交于 2020-06-29 03:40:37
问题 I have created a form in html with some basic information like Website, Link, Name, Last_name, email and price. I am trying to add new columns into my sql database from the html forms. ##When I do it in this way it works fine: from flask import Flask from flask_sqlalchemy import SQLAlchemy app=Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI']='mysql://root:password@localhost/db_name' db=SQLAlchemy(app) class Feedback(db.Model): __tablename__='user' website=db.Column('website',db.String(20

Flask-SQLALchemy update record automatically after specific time

大城市里の小女人 提交于 2020-06-28 04:46:28
问题 I have a db models like this: class Payment(db.Model): id = db.Column(db.Integer(), primary_key=True) user_id = db.Column(db.Integer(), db.ForeignKey('user.id')) ticket_status = db.Column(db.Enum(TicketStatus, name='ticket_status', default=TicketStatus.UNUSED)) departure_time = db.Column(db.Date) I want to change the value from all ticket_status after datetime.utcnow() passed the date value from departure_time . I tried to code like this: class TicketStatus(enum.Enum): UNUSED = 'UNUSED' USED

models are not detectable by flask migrate

做~自己de王妃 提交于 2020-06-27 22:12:13
问题 I have this tree in my flask application: -- api -- migrations -- model -- __init__.py -- Persons.py -- Comments.py -- other_classes.py -- resources -- __init__.py -- app.py -- util.py This is __init_.py from model directory: from os.path import dirname, basename, isfile import glob modules = glob.glob(dirname(__file__)+"/*.py") __all__ = [ basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')] from .Persons import Persons This is util.py from flask import Flask

ImportError: No module named 'flask_sqlalchemy' w/ 2 Versions of Python Installed

天涯浪子 提交于 2020-06-27 13:27:47
问题 Tried running a file with the following imports: from flask_sqlalchemy import sqlalchemy from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker Received the following error: ImportError: No module named 'flask_sqlalchemy' SQLAlchemy is installed. Still, I tried to reinstall into the directory in which it will be used. I got this: The directory '/Users/_/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has

How do i implement a like button function to posts in Python Flask?

情到浓时终转凉″ 提交于 2020-06-24 16:40:56
问题 So i am trying to add to add a like button feature to my code that allows users to like specific posts. The likes will be linked to a logged in user and the number of likes will be shown. Implementing the front end wont be difficult but i am having a problem with the back end. I am using this post here as a guide which does a follower system instead This is what I have so far? I have created a table for likes in models.py : likers = db.Table('likers', db.Column('liker_id', db.Integer, db