[Fixed]-Django rest-farmework nested relationships to pass parameters

1👍

You can access the serializer context:

def get_sources(self, category):
    num_parameter = self.context['request'].query_params['num']
    sources = category.source_set.filter(amount=num_parameter)

In your case, you need to pass the context when instantiating the serializer:

CategorySerializers(category, many=True, context={'request': request})

This is usually done automatically when using generic GenericAPIViews.

Leave a comment