class LiteDocumentSerializer(serializers.ModelSerializer): """ # light document serializer (to be used in manytomany retrieve) """ snapshot = OptionalFileField() attachment = OptionalFileField() class Meta: model = Document fields = ('id', 'title', 'slug', 'mimetype', 'type', 'data', 'url', 'attachment', 'snapshot')
class CreateDocumentSerializer(serializers.ModelSerializer): owner = serializers.HiddenField( default=serializers.CurrentUserDefault() ) snapshot = OptionalFileField(read_only=True) attachment = OptionalFileField(required=False) class Meta: model = Document fields = ('id', 'owner', 'type', 'data', 'short_url', 'title', 'slug', 'copyrights', 'url', 'attachment', 'snapshot', 'mimetype')
class MatchingDocumentSerializer(serializers.ModelSerializer): matches = HitField() src = OptionalFileField(source='attachment') class Meta: model = Document fields = ('id', 'url', 'src', 'data', 'type', 'slug', 'title', 'matches')
class DocumentSerializer(LiteDocumentSerializer): src = OptionalFileField(source='attachment') documents = LiteDocumentSerializer(many=True) class Meta: model = Document fields = ('id', 'url', 'src', 'data', 'type', 'slug', 'title', 'snapshot', 'copyrights', 'attachment', 'documents', 'locked')
class CaptionSerializer(serializers.HyperlinkedModelSerializer): document_id = serializers.ReadOnlyField(source='document.id') type = serializers.ReadOnlyField(source='document.type') title = serializers.ReadOnlyField(source='document.title') slug = serializers.ReadOnlyField(source='document.slug') src = OptionalFileField(source='document.attachment') short_url = serializers.ReadOnlyField(source='document.short_url') copyrights = serializers.ReadOnlyField(source='document.copyrights') caption = serializers.ReadOnlyField(source='contents') data = JsonField(source='document.data') snapshot = OptionalFileField(source='document.snapshot', read_only=True) attachment = OptionalFileField(source='document.attachment', read_only=True) class Meta: model = Caption fields = ('id', 'document_id', 'title', 'slug', 'type', 'copyrights', 'caption', 'short_url', 'src', 'snapshot', 'attachment', 'data')