[Answer]-How to inline ManyToMany fields in JSON with Tastypie?

1👍

✅

I’ve ran your code and got the following response

{"meta": 
{"limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 1}, 
"objects": [
{"filename": "10.jpg", "resource_uri": "/api/image/1/", 
"tags": [{"name": "portrait", "resource_uri": "/api/tags/1/"}, 
  {"name": "B&W", "resource_uri": "/api/tags/2/"}]}]}

So I think your definitions in Tastypie are correct. Are you sure you’ve added the objects properly to the DB?

My test code:

    im = Image(filename='10.jpg')
    im.save()
    tags = [Tag(name='portrait'),Tag(name='B&W')]
    for tag in tags:
        tag.save()
    im.tags.add(*tags)
    resp = self.client.get('/api/image/')

Leave a comment