[Flask] Querying flask-appbuilder model using sqlalchemy

Jim Icenhower jicenhower at yahoo.com
Tue Sep 1 16:21:49 CEST 2015


Hi all,
I'm creating an app using Flask-Appbuilder and trying to use Flask-Excel which is pyexcel to export records based on a class named Event implementing the Model class. I can use the pyexcel I'd like to do this the pyexcel make_response_from_tables() method but I want to control the order in which the columns are output. I will eventually also want to filter the output records so I need some control over the output.
I would like to do this the most correct way, hopefully using the Event class to return the data. Can anyone give me a nudge in the right direction to do this?
The current error I'm receiving is "AttributeError: 'Query' object has no attribute 'query'". What should I do or where should I look for detailed guidence?
Thanks!
In models.py:
(snipped of imports)from sqlalchemy import Column, Integer, Float, String, ForeignKey, Text, Datefrom flask.ext.appbuilder import Model
class Event(Model):    EventID = Column(Integer, primary_key=True)    Name = Column(String(100), unique=True, nullable=False)    Description = Column(Text(1000), unique=True, nullable=False)    BeginDate = Column(Date, unique=True, nullable=False)    EndDate = Column(Date, unique=True, nullable=False)
    def __repr__(self):        return self.Name
In views.py:
(snippet of imports)from flask.ext import excelfrom pyexcel.ext import xlsx, xls

@app.route("/export_events", methods=['GET'])def export_events():    datamodel = SQLAInterface(Event)    column_names=['EventId','Description']    db.session.query(Event).query.all()    return excel.make_response_from_query_sets(query_sets, column_names, "xls")

Thanks for any help!     Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20150901/814d5f2d/attachment.html>


More information about the Flask mailing list