You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Though late to the party but you could have done it easliy like this 'barcodes': fields.List(fields.String, attribute=lambda p: [product.code for product in p.barcodes])
I asked this question on StackOverflow (here) but didn't get any help there. I'm sure that there is a simple answer to this.
I'm using
flask_restplus
to build an API.I have two models:
and
The relationship between
Product
andBarcode
is many-to-many.The API response looks like this:
However, since the contents of the barcode model are just a single field I want it to marshal like this instead:
How would I do this?
I've tried wrapping the call to
fields.Nested()
infields.List()
but that did not help.If anybody has an idea of how to make this work, I'd really appreciate the help!
Thanks.
Background Information
Here are the relevant package versions:
Database Classes
Here are the definitions of the SQLAlchemy classes:
Alternative Implementation
I have a working implementation using Marshmallow.
This does precisely what I want. However I'd really prefer to use
flask_restplus
models because they make the code for the actual API a lot neater.The text was updated successfully, but these errors were encountered: