3

我有以下设置:

#models.py
class Image(models.Model):
    original = models.ImageField(upload_to='images/')
    formatted_image = ImageSpecField(source='original', format='JPEG', options={'quality': 90})


#serializers.py
class ImageSerializer(serializers.ModelSerializer):
    class Meta:
        model = Image

#views.py
class ImageViewSet(viewsets.ModelViewSet):
    model = Image
    serializer_class = ImageSerializer

根据 ImageKit 文档,这应该可以解决问题,但实际上什么也没发生。甚至没有错误或任何东西。我究竟做错了什么?

4

1 回答 1

1
#serializers.py
class ImageSerializer(serializers.ModelSerializer):
    formatted_image = serializers.ImageField()
    class Meta:
        model = Image

这对我有用。

于 2017-11-05T21:36:15.297 回答