<s> from rest_framework import relations , serializers <EOL> from tests import models <EOL> import rest_framework <EOL> class CommentSerializer ( serializers . HyperlinkedModelSerializer ) : <EOL> class Meta : <EOL> fields = ( "<STR_LIT:id>" , "<STR_LIT:url>" , "<STR_LIT>" , "<STR_LIT:body>" , ) <EOL> model = models . Comment <EOL> class PersonSerializer ( serializers . HyperlinkedModelSerializer ) : <EOL> class Meta : <EOL> fields = ( "<STR_LIT:id>" , "<STR_LIT:url>" , "<STR_LIT:name>" , ) <EOL> model = models . Person <EOL> class PostSerializer ( serializers . HyperlinkedModelSerializer ) : <EOL> class Meta : <EOL> fields = ( "<STR_LIT:id>" , "<STR_LIT:url>" , "<STR_LIT:title>" , "<STR_LIT>" , "<STR_LIT>" , ) <EOL> model = models . Post <EOL> class MaximalPersonSerializer ( serializers . HyperlinkedModelSerializer ) : <EOL> class Meta : <EOL> fields = ( "<STR_LIT:id>" , "<STR_LIT:url>" , "<STR_LIT:name>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> model = models . Person <EOL> class MinimalCommentSerializer ( CommentSerializer ) : <EOL> class Meta ( CommentSerializer . Meta ) : <EOL> fields = ( "<STR_LIT:id>" , "<STR_LIT:url>" , "<STR_LIT:body>" , ) <EOL> class MinimalPostSerializer ( PostSerializer ) : <EOL> class Meta ( PostSerializer . Meta ) : <EOL> fields = ( "<STR_LIT:id>" , "<STR_LIT:url>" , "<STR_LIT:title>" , ) <EOL> class NestedCommentSerializer ( CommentSerializer ) : <EOL> post = MinimalPostSerializer ( ) <EOL> class NestedPostSerializer ( PostSerializer ) : <EOL> comments = MinimalCommentSerializer ( many = True ) <EOL> class PkCommentSerializer ( CommentSerializer ) : <EOL> post = relations . PrimaryKeyRelatedField ( queryset = models . Post . objects ) <EOL> single_related_kwargs = { } <EOL> if rest_framework . __version__ . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] >= "<STR_LIT:3>" : <EOL> single_related_kwargs = { "<STR_LIT>" : True } <EOL> class PkMaximalPersonSerializer ( MaximalPersonSerializer ) : <EOL> favorite_post = relations . PrimaryKeyRelatedField ( required = False , queryset = models . Post . objects , ** single_related_kwargs ) <EOL> liked_comments = relations . PrimaryKeyRelatedField ( required = False , many = True , queryset = models . Comment . objects ) </s>
