Created
May 9, 2015 09:50
-
-
Save ijharulislam/f0ef0c8b6b89b70d559b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Book(models.Model): | |
name = models.CharField(max_length= 200) | |
author = models.CharField(max_length=100) | |
publisher = models.CharField (max_length = 200) | |
class Chapter (models.Model): | |
book = models.ForeignKey(Book, related_name ='chapter') | |
title = models.CharField(max_length=300) | |
class Section (models.Model): | |
chapter = models.ForeignKey(Chapter, related_name='section') | |
body = models.TextField() | |
class BookSerializer(serializers.ModelSerializer): | |
chapter = serializers.SlugRelatedField( | |
many=True, | |
read_only=True, | |
slug_field='title' | |
) | |
class Meta: | |
model = Book | |
fields = ('name', 'author', 'chapter') | |
class ChapterSerializer(serializers.ModelSerializer): | |
section = serializers.HyperlinkedRelatedField( | |
many=True, | |
read_only=True, | |
view_name='section-detail' | |
) | |
class Meta: | |
model = Chapter | |
fields = ('body', 'section') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment