Finally, I found the answer by going through the tastypie code. It turned out that the model field in the definition of the ToMany relation ( topping_set here) can be set to the called one.
Inside the called, you get only the bundle parameter of the data used to dehydrate the received data. There is always a request inside this bundle , so the user instance that I want to use for filtering.
So, I did this:
toppings = fields.ToManyField( 'project.app.api.ToppingResource', 'topping_set' )
:
toppings = fields.ToManyField( 'project.app.api.ToppingResource', lambda bundle: Topping.objects.filter( pizza=bundle.obj, used_by=bundle.request.user ) )
and it's all!
source share