0

In my model I have, for now, 3 classes:

  • Quest: Basics attributes of quest
  • GoToAndAnswer: Kinda type of a quest, which extends Quest
  • SeekAndAnswer: Same as above, extending Quest

I'm using Django to build an API so in my View I want to print the info about these Quests in JSON format. The problem is I don't know how to serialize the objects correctly (Im really new at Django and Python):

# Only get the attributes of the class Quest, obviously
serializers.serialize("json", Quest.objects.all())

# Only get the atributes of the GoToAndAnswer, nothing about the Quest attributes
serializers.serialize("json", GoToAndAnswer.objects.all())

So which is the best way to achieve this?

I have seen posts like this: JSON Serialization of a Django inherited model

But it didnt help...

Thanks in advance

Community
  • 1
  • 1
João Menighin
  • 3,083
  • 6
  • 38
  • 80

1 Answers1

0

You might want to take a look at Django REST Framework which solves all your problems.

That's a Django app with a excellent documentation and all the tools you need to create a API. http://www.django-rest-framework.org/

Jay
  • 2,519
  • 5
  • 25
  • 42