36👍
✅
When using ViewSets, you can access the request in the serializer context (like you access the view). You can access the query params from this
def get_alternate_name(self, obj):
request = self.context['request']
print request.query_params['q']
return 'foo'
The attribute view.kwargs contains the named arguments parsed from your url-config, so from the path-part.
9👍
- [Django]-Django update table using data from another table
- [Django]-Dynamically add field to a form
- [Django]-How to write a unit test for a django view?
- [Django]-Django Models (1054, "Unknown column in 'field list'")
- [Django]-Understanding ManyToMany fields in Django with a through model
- [Django]-How to reload modules in django shell?
Source:stackexchange.com