Issue with Flask-Marshmallow exposing DB contents via API
<p>I am developing a API which will return entries from a Database. I am using Flask-SQLAlchemy, Flask-Marshmallow, Flask-Admin and Docker to package it all up. </p>

<p>In one file Packages.py I have the following code regarding the database. The class PckagesSchema is the class I've added when trying to get Flash-Marshmallow working.</p>

<pre><code>class Packages(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    trackingnumber = db.Column(db.String(15))
    email = db.Column(db.String(80))
    localid = db.Column(db.String(80))

class PackagesSchema(ma.ModelSchema):
    class Meta:
        model = Packages
</code></pre>

<p>The in the main file I have the following snippets of code</p>

<pre><code>from app.models import Packages, PackagesSchema
packages_schema = PackagesSchema()
db.create_all()
</code></pre>

<p>and then further down the part which will deal with API GET Requests. </p>

<pre><code>@app.route('/packages', methods=['GET'])
def get_packages():
    result = packages_schema.dump(Packages).data
    return jsonify(result)
</code></pre>

<p>at the moment this returns:</p>

<pre><code>{
  "email": "Packages.email", 
  "localid": "Packages.localid", 
  "trackingnumber": "Packages.trackingnumber"
}   
</code></pre>

<p>However, there is definitely something in the database as the Flask-Admin app displays its.</p>

<p>This is my first day working with Flask-Marshmallow so I am not that experienced at all and would appreciate any help. I have read
<a href="https://flask-marshmallow.readthedocs.io/en/latest/" rel="nofollow">https://flask-marshmallow.readthedocs.io/en/latest/</a>
but still stuck. </p>

<p>I just brushed up a little on marshmallow:</p>

<pre><code>@app.route('/packages', methods=['GET'])
def get_packages():
    packages = Packages.query.all()
    result = packages_schema.dump(packages).data
    return jsonify(result)
</code></pre>

<p>Should give you everything in there.  If you are returning many records, you need to add <code>packages_schema = PackagesSchema(many=True)</code>.</p>

<p>Also, not sure what version of flask you are running... but pre the latest release, I dont think jsonify would work here since you could not call it on a list.  Juts a heads up.</p>

python flask flask-sqlalchemy marshmallow