3

Suppose you have a BaseClass and ChildClass1, ChildClass2 with its own fields.

I want to give create a url end point where I can return a list of mixed models with their own fields included.

[
 childClass1_obj1,
 childClass2_obj2,
 childClass1_obj3
]

I have serializers for each type already setup, and would be good to reuse it somewhere, but if that's not possible, I can live with any solution that works.

Return results from multiple models with Django REST Framework talks about similar stuff, but he only serializes the common part of the two.

3
  • 1
    There is an answer here that might help: stackoverflow.com/questions/19976202/… Commented Oct 15, 2014 at 14:59
  • @HairyChris: wow, that one is close.. I tried polymorphic-models, but didn't get it to work (probably due to the fact my models has additional related fields to each other other than parent_link).. I actually tried overriding to_native , but didn't quite get it to work either. Commented Oct 15, 2014 at 16:01
  • This is another approach: stackoverflow.com/questions/24048595/… but the author mentions potential performance problems. Commented Oct 15, 2014 at 16:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.