Answer the question
In order to leave comments, you need to log in
Loading and saving multiple images in M2M field Django Rest?
No matter how I tried, I could not fill the dictionary with validated_data
a list of images that is sent to the server.
The key images
is not in the dictionary, the method validate_images
does not run. C cover_image
everything is all right Tell me
, is it possible to fill the dictionary validated_data
with a validated list of images (InMemoryUploadFile), other than how to get raw files from request.FILES
?
Am I sending via PostMan correctly?
class Image(models.Model):
name = models.CharField(max_length=255, blank=True)
image = models.ImageField(upload_to='images/', validators=[validation_existing_image])
class Address(models.Model):
cover_image = models.ForeignKey(Image, on_delete=models.SET_NULL, null=True, related_name='+', blank=True)
images = models.ManyToManyField(Image, related_name='+', blank=True)
class UpdateAddressSerializer(serializers.ModelSerializer):
cover_image = serializers.ImageField()
images = serializers.ListSerializer(child=serializers.ImageField())
class Meta:
model = Address
fields = '__all__'
def validate_images(self, value):
return value
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question