[EDITED]
I have any api using flask + connexion (swagger 2.0)
Any time I retrieve a collection from the database, using simple code such as:
# GET /api/model
def get_all_model():
return Model.objects
I get the following error:
TypeError: [Model] is not JSON serializable
As a workaround, I have done the following
def get_all_model():
return json.loads(model.objects.to_json())
How can I return the entire collection without serializing/deserializing?
from the docs:
Document classes have an objects attribute, which is used for accessing the objects in the database associated with the class. The objects attribute is actually a QuerySetManager, which creates and returns a new QuerySet object on access. The QuerySet object may be iterated over to fetch documents from the database: