Django DRF image field does not accept null values.
My model consists of image = models.ImageField(upload_to='uploads/', blank=True, null=True)
If I upload a file there's no problem. But, if I leave it blank it gives the following error:
The submitted data was not a file. Check the encoding type on the form.
I want to make the image field optional So I set null=True and blank=True. But this does not seem to work.
In DRF your model passes through serializer add this to your serializer:
class ImagePostSerializer(serializers.ModelSerializer):
image = serializers.ImageField(required=False)
class Meta:
model = models.ImagePost
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With