class MatchingDocumentSerializer(serializers.ModelSerializer): matches = HitField() src = OptionalFileField(source='attachment') class Meta: model = Document fields = ('id', 'url', 'src', 'data', 'type', 'slug', 'title', 'matches')
class MatchingStorySerializer(serializers.HyperlinkedModelSerializer): authors = AuthorSerializer(many=True) owner = UserSerializer() tags = TagSerializer(many=True) covers = LiteDocumentSerializer(many=True) matches = HitField() def is_named_bar(self, foo): return foo.name == "bar" class Meta: model = Story fields = ('id', 'url', 'slug', 'short_url', 'title', 'abstract', 'date', 'date_created', 'status', 'covers', 'data', 'authors', 'tags', 'owner', 'matches')