[Django]-Django Tastypie include count on many-to-many fields

5👍

You can add a custom count field. You need to implement dehydrate method in your resource.
Something like this should work for you:

class MovieResource(ModelResource):
  def dehydrate(self, bundle):
    bundle.data['actor_count'] = bundle.obj.actors.count()
    return bundle

Docs here

Leave a comment