[Solved]-Django REST Framework and generic relations

8👍

Your right, REST framework doesn’t support those use cases, and its not obvious to me what the design would look like if it did. You’d probably need an implicit registry of model->view (for the hyperlinked case) and model-> serializer (for the nested case) which I don’t think I’d be very keen on.

The simplest way to do what you need is probably to subclass ManyRelatedField and create a custom field type, overriding to_native(self, obj) to serialize each object in the set exactly the way you want it.

Leave a comment