Hello, all! I've posted my question to StackOverflow but the two responses there don't seem to resolve me issue.
https://stackoverflow.com/questions/48676365/how-can-i-clear-an-image-with-django-rest-framework class Part(models.Model): image = models.ImageField(null=True, blank=True) class PartSerializer(serializers.ModelSerializer): class Meta: model = Part fields = ('id', 'image') class PartDetail(generics.RetrieveUpdateAPIView): queryset = Part.objects.all() serializer_class = PartSerializer parser_classes = (MultiPartParser, FormParser) # put image, works fine with tempfile.NamedTemporaryFile(suffix='.jpg') as fp: image = Image.new('RGB', (100, 200)) image.save(fp) fp.seek(0) data = {'image': fp} self.client.put('/path/to/endpoint', data, format='multipart') # clear image, attempt #1 data = {'image': None} self.client.put('/path/to/endpoint', data, format='multipart') # AssertionError: {'image': ['The submitted data was not a file. Check the encoding type on the form.']} # clear image, attempt #2 data = {'image': ''} self.client.put('/path/to/endpoint', data, format='multipart') # AssertionError: <ImageFieldFile: None> is not None Using Django 1.11 and DRF 3.7, I'm sending a PUT to clear an image on a model by setting it to None, or empty-string, and getting back an error either way. What's the "correct" way to clear an image from a model using DRF? -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
