Python rest_framework.serializers.FileField() Examples

The following are 2 code examples of rest_framework.serializers.FileField(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module rest_framework.serializers , or try the search function .
Example #1
Source File: serializers.py    From django-spillway with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_fields(self):
        fields = super(RasterModelSerializer, self).get_fields()
        if not self.Meta.raster_field:
            for name, field in fields.items():
                if isinstance(field, serializers.FileField):
                    self.Meta.raster_field = name
                    break
        fieldname = self.Meta.raster_field
        request = self.context.get('request')
        renderer = getattr(request, 'accepted_renderer', None)
        try:
            obj = self.instance[0]
        except (IndexError, TypeError):
            obj = self.instance
        modelfield = getattr(obj, fieldname, None)
        if (isinstance(renderer, BaseGDALRenderer)
                or not isinstance(modelfield, FieldFile)):
            fields[fieldname] = serializers.ReadOnlyField()
        return fields 
Example #2
Source File: test_field_converter.py    From graphene-django with MIT License 5 votes vote down vote up
def test_should_file_convert_string():
    assert_conversion(serializers.FileField, graphene.String)