wimglenn / djangorestframework-queryfields

Allows clients to control which fields will be sent in the API response
http://djangorestframework-queryfields.readthedocs.io/
MIT License
215 stars 16 forks source link

Omit expensive field by default #20

Open btimby opened 5 years ago

btimby commented 5 years ago

I have a field that I want to exclude by default and only include when requested. This is currently not possible (AFAICT).

Any insight on how I could implement this in a PR?

Thanks.

caleb-harrelson commented 5 years ago

I needed this too, so I forked and threw something together. Here's my commit. It works for ModelSerializers, but not plain serializers, and has no tests, so it's only a starting point if you want to build a PR off of it.

Also note that QueryFieldsMixin prevents the serialization of fields, but not the querying in whatever uses the serializer. If you're optimizing for expensive queries, instead of expensive serialization, you'll need to optimize elsewhere too.