I want to serialize a queryset of an object which has a one-to-many relationship to another model. I want to include the related objects in my json output.
Example:
class Book(models.Model):
title = models.CharField()
author = models.ForeignKey('Author')
class Author(models.Model):
name = models.CharField()
view.py:
serializers.serialize('json', Author.objects.all()) #does not include the book objects
I am pretty sure there is an easy solution, but so far I was not able to figure out how to do it. Thanks for your help!