FAQ¶
- Q:
Can I use this with vanilla serializers as well as
ModelSerializer
?- A:
Sure. You’ll need include the request in the context, to provide access on the querystring:
MySerializer(obj, context={'request': request})
- Q:
The name
fields
conflicts with some other functionality in my API (e.g. django-filter). Can I change it to something else?- A:
Yep. Override a couple of attributes on the class, and then Python’s MRO will take care of the rest. For example:
class MyModelSerializer(QueryFieldsMixin, ModelSerializer):
include_arg_name = 'include'
exclude_arg_name = 'exclude'
delimiter = '|'
Now request like GET /things/?exclude=key2|key3
instead of the default GET /things/?fields!=key2,key3
.
New in v1.1.0: The Django settings module may also be used, for example:
# in settings.py
DRF_QUERYFIELDS_INCLUDE_ARG_NAME = 'gimme'
DRF_QUERYFIELDS_EXCLUDE_ARG_NAME = 'omit'
DRF_QUERYFIELDS_DELIMITER = '+'
- Q:
This thing broke, you suck… / Hey, wouldn’t it be cool if…
- A:
Well, that’s not really a question, pal. For feature requests or bug reports, please create an issue here.