Using SelectFields with flask-wtforms !HELP!
I'm having issues using Select Field in flask . I'm unable to submit get data from the select fields , also when i use them with normal input fields none of the fields return any data . But the input fields work and return data if I remove the selectFields . Here's the code :
Models and form :
class City(db.Model):
id = db.Column(db.Integer, primary\_key=True)
city = db.Column(db.String(30), unique=True, nullable=False)
state = db.Column(db.String(30), nullable=False)
country = db.Column(db.String(30), nullable=False)
class CityForm(FlaskForm):
city = StringField('city', validators=\[InputRequired()\])
state = SelectField('state' , validators=\[InputRequired()\] , coerce = str)
country = SelectField('country' , validators=\[InputRequired()\] , coerce = str)
the select fields are populated in the views , like this :
form\_city.state.choices = \[(row\[0\],row\[0\]) for row in db.session.query(login\_model.State.state)\]
form\_city.country.choices = \[(row\[0\],row\[0\]) for row in db.session.query(login\_model.Country.country)\]
\~\~\~\~\~
if form\_city.validate\_on\_submit():
mssg = ""
prod = login\_model.City.query.filter\_by(city=form\_city.city.data).first()
print('okaaay')
if prod :
mssg = "Duplicate Data "
flash(mssg)
return redirect(url\_for('basic\_master'))
else:
new\_data = login\_model.City(city=form\_city.city.data.upper())
try:
db.session.add(new\_data)
db.session.commit()
mssg = "Data Successfully added π"
flash(mssg)
return redirect(url\_for('basic\_master'))
except Exception as e:
mssg = "Error occured while adding data π΅. Here's the error : "+str(e)
flash(mssg)
return redirect(url\_for('basic\_master'))
Nothing works if I have selectfields in my Form class , and If i remove them the normal input field works .
Any help is much appreciated thanks.
\#flask #sqlalchemy #wtforms #python
/r/flask
https://redd.it/8srquo
I'm having issues using Select Field in flask . I'm unable to submit get data from the select fields , also when i use them with normal input fields none of the fields return any data . But the input fields work and return data if I remove the selectFields . Here's the code :
Models and form :
class City(db.Model):
id = db.Column(db.Integer, primary\_key=True)
city = db.Column(db.String(30), unique=True, nullable=False)
state = db.Column(db.String(30), nullable=False)
country = db.Column(db.String(30), nullable=False)
class CityForm(FlaskForm):
city = StringField('city', validators=\[InputRequired()\])
state = SelectField('state' , validators=\[InputRequired()\] , coerce = str)
country = SelectField('country' , validators=\[InputRequired()\] , coerce = str)
the select fields are populated in the views , like this :
form\_city.state.choices = \[(row\[0\],row\[0\]) for row in db.session.query(login\_model.State.state)\]
form\_city.country.choices = \[(row\[0\],row\[0\]) for row in db.session.query(login\_model.Country.country)\]
\~\~\~\~\~
if form\_city.validate\_on\_submit():
mssg = ""
prod = login\_model.City.query.filter\_by(city=form\_city.city.data).first()
print('okaaay')
if prod :
mssg = "Duplicate Data "
flash(mssg)
return redirect(url\_for('basic\_master'))
else:
new\_data = login\_model.City(city=form\_city.city.data.upper())
try:
db.session.add(new\_data)
db.session.commit()
mssg = "Data Successfully added π"
flash(mssg)
return redirect(url\_for('basic\_master'))
except Exception as e:
mssg = "Error occured while adding data π΅. Here's the error : "+str(e)
flash(mssg)
return redirect(url\_for('basic\_master'))
Nothing works if I have selectfields in my Form class , and If i remove them the normal input field works .
Any help is much appreciated thanks.
\#flask #sqlalchemy #wtforms #python
/r/flask
https://redd.it/8srquo
reddit
r/flask - Using SelectFields with flask-wtforms !HELP!
1 votes and 3 so far on reddit
New Fask library to make uploading, storing & streaming files easy!
Hi guys
I have just finished work on a new Flask library to make uploading files and storing them on your server & database as easy as possible... just let Flask-File-Upload handle all the repetitive work!
Works with Flask & Flask-SQLAlchemy
[https://github.com/joegasewicz/Flask-File-Upload](https://github.com/joegasewicz/Flask-File-Upload)
​
I would be very grateful if anyone wishes to try out this library & or give some feed back. And of course contributions are welcome!
Thanks so much
Joe
​
https://preview.redd.it/ppd6fr092g941.jpg?width=2200&format=pjpg&auto=webp&s=9fe80a5d18d313158672805eddb42edbfd1de506
\#python #flask #sqlalchemy
/r/flask
https://redd.it/elk36d
Hi guys
I have just finished work on a new Flask library to make uploading files and storing them on your server & database as easy as possible... just let Flask-File-Upload handle all the repetitive work!
Works with Flask & Flask-SQLAlchemy
[https://github.com/joegasewicz/Flask-File-Upload](https://github.com/joegasewicz/Flask-File-Upload)
​
I would be very grateful if anyone wishes to try out this library & or give some feed back. And of course contributions are welcome!
Thanks so much
Joe
​
https://preview.redd.it/ppd6fr092g941.jpg?width=2200&format=pjpg&auto=webp&s=9fe80a5d18d313158672805eddb42edbfd1de506
\#python #flask #sqlalchemy
/r/flask
https://redd.it/elk36d
GitHub
joegasewicz/flask-file-upload
Easy file uploads for Flask. Contribute to joegasewicz/flask-file-upload development by creating an account on GitHub.
Simple syntax question- how to drop one table in SQL Alchemy / Flask?
The Flask documentation seems to only discuss how to drop ALL the tables:
https://flask-sqlalchemy.palletsprojects.com/en/2.x/binds/#creating-and-dropping-tables
I don't know how to interpret this, https://docs.sqlalchemy.org/en/14/core/metadata.html#sqlalchemy.schema.Table.drop. I'm not sure if it would apply to working in Flask.
All the online answers regarding deleting one table in SQL Alchemy discuss it as engine, not, as one stackoverflow user says, a "Flask-SQLAlchemy extension object".
I need to drop a table every time the app runs because the app automatically populates this table with data. If it tries to populate a populated table, it will get a "UNIQUE" error.
On my init.py I have:
~~~
from flasksite.models import Styletable
db = SQLAlchemy(app)
db.dropall()
db.createall()
Styletable.createtable()
~~~
This works great to populate the data. But, it drops all the data from all the tables. That's not good.
I wish I could just do something like
db.drop(Styletable)
or
db.Styletable.drop()
on my models.py I have:
~~~~
class Styletable(db.Model):
id = db.Column(db.Integer, primarykey=True)
stylename = db.Column(db.String(100), primarykey=True, nullable= False)
def createtable():
a = Styletable()
b = Styletable()
c = Styletable()
a.stylename = "essay"
/r/flask
https://redd.it/pqmj4g
The Flask documentation seems to only discuss how to drop ALL the tables:
https://flask-sqlalchemy.palletsprojects.com/en/2.x/binds/#creating-and-dropping-tables
I don't know how to interpret this, https://docs.sqlalchemy.org/en/14/core/metadata.html#sqlalchemy.schema.Table.drop. I'm not sure if it would apply to working in Flask.
All the online answers regarding deleting one table in SQL Alchemy discuss it as engine, not, as one stackoverflow user says, a "Flask-SQLAlchemy extension object".
I need to drop a table every time the app runs because the app automatically populates this table with data. If it tries to populate a populated table, it will get a "UNIQUE" error.
On my init.py I have:
~~~
from flasksite.models import Styletable
db = SQLAlchemy(app)
db.dropall()
db.createall()
Styletable.createtable()
~~~
This works great to populate the data. But, it drops all the data from all the tables. That's not good.
I wish I could just do something like
db.drop(Styletable)
or
db.Styletable.drop()
on my models.py I have:
~~~~
class Styletable(db.Model):
id = db.Column(db.Integer, primarykey=True)
stylename = db.Column(db.String(100), primarykey=True, nullable= False)
def createtable():
a = Styletable()
b = Styletable()
c = Styletable()
a.stylename = "essay"
/r/flask
https://redd.it/pqmj4g
Optimizing our longest nightly job β a story of sessions, complexity, and toilets #SQLAlchemy #Performance
https://medium.com/alan/blog-post-optimizing-our-longest-nightly-job-a-story-of-sessions-complexity-and-toilets-750ef4dfaa51
/r/Python
https://redd.it/106fxa6
https://medium.com/alan/blog-post-optimizing-our-longest-nightly-job-a-story-of-sessions-complexity-and-toilets-750ef4dfaa51
/r/Python
https://redd.it/106fxa6
Medium
Optimizing our longest nightly job β a story of sessions, complexity, and toilets
Last year, James (the founding father of the Alan claim engine) shared some details about how the engine works, its requirements andβ¦