0

I have several serializers with related fields or serializers as fields, but with the default configuration of Django Rest Framework, either everything is dumped, or only the ID, or a URL.

I want to be able to control the verbosity of the representation a bit more:

  • sometime I want just the ID or my related field;
  • sometime I want the full object dump.
  • I may want the ID in ouput, and the dump in output.

Right now I have to serialize everything manually because I can't find a quick and easy way to tell DRF, hey, here just do this.

Is there such a way ?

Bite code
  • 578,959
  • 113
  • 301
  • 329
  • As of now you can just specify all fields and exclude them like this http://stackoverflow.com/questions/27935558/dynamically-exclude-or-include-a-field-in-django-rest-framework-serializer#27936077 whenever needed. – dnit13 Sep 14 '16 at 06:55
  • I don't want to exclude fields, that would end up with {'id': 1}, and for the id part, I just want the id, not the dict around it. – Bite code Sep 14 '16 at 08:11
  • Unfortunately no inbuilt support for this as far as I know. I usually end up using two serializers when my input takes ids and output needs the whole object dumps. But I guess this can be customized. – dnit13 Sep 14 '16 at 08:27
  • By manually serializing you mean you manually define fields you want to serialize inside a serializer? How do you want it to behave instead, the fields need to be listed somewhere one way or another. – serg Sep 15 '16 at 03:36
  • No I mean defining 2 serializers and calling them manually inside the other serializer. – Bite code Sep 15 '16 at 07:30

0 Answers0