I am using the flask-marshmallow package's HyperlinkRelatedField
and wanted to know if it was possible to add query-string parameters dynamically with one of the provided fields (either a field from flask marshmallow or marshmallow like HyperlinkRelatedField
). I want this:
/api/v1/cars?manufacturer=12
Where manufacturer Id in the querystring is the ID of the serialized object and cars is the hyperlink related field. I am working with a flattened API so linking fields with a many relationship would need to be done with filtering So this would be something like the Schema (this doesn't work but an example of what I am looking to achieve):
class ManufacturerSchema(ma.ModelSchema):
cars = HyperlinkRelated('api.carslist', params={'manufacturer': '<id>'})
class Meta:
model = Manufacturer
sqla_session = db.session
Where:
manufacturer = Manufacturer.query.get(1) # ID is 1
ms = ManufacturerSchema()
ms.dump(manufacturer)
Would return:
{
...
'cars': '/api/v1/cars?manufacturer=1',
...
}
How would I achieve this? Is it possible with the provided Marshmallow/Flask-Marshmallow Fields, or would I have to subclass HyperLinkRelated or Field?