custom serializer Field, ListSerializer, and current instance?

19 views
Skip to first unread message

Christian Sauer

unread,
Sep 20, 2016, 3:25:12 PM9/20/16
to Django REST framework

I'm building a couple of custom serializer Fields and I need access to the whole instance to make a decision on what to return.  If the serializer represents a single object, the field can use "self.parent.instance" to get the whole thing and everything works great.  When the parent is ListSerializer (actual serial is now self.child), there doesn't seem to be a way to get the current instance.  In that case, the code execution is Serializer.to_representation where instance is passed in but not made accessible nor passed down to the field.

Is this a bug or should I be doing something differently?

~CS


Reply all
Reply to author
Forward
0 new messages