本文整理汇总了Python中rest_framework.serializers.FileField方法的典型用法代码示例。如果您正苦于以下问题:Python serializers.FileField方法的具体用法?Python serializers.FileField怎么用?Python serializers.FileField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework.serializers
的用法示例。
在下文中一共展示了serializers.FileField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_fields
# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import FileField [as 别名]
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
示例2: test_should_file_convert_string
# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import FileField [as 别名]
def test_should_file_convert_string():
assert_conversion(serializers.FileField, graphene.String)