Hello, suppose I have the following code:
class BizProfile(models.Model):
title = models.CharField(max_length=100)
description = models.CharField(max_length=500, default="", blank=True)
profile_image = models.ImageField(max_length=200, blank=True, null=True)
banner_image = models.ImageField(max_length=200, blank=True, null=True)
class BizHasPhoto(models.Model):
biz_profile = models.ForeignKey(BizProfile)
photo = models.ImageField(max_length=200)
description = models.CharField(max_length=300, default="", blank=True)
serializers and views are default.
I get HTTP 200 when running the following test:
profile_image = open('valid_profile_image.jpg', 'rb')
banner_image = open('valid_banner_image.jpg', 'rb')
data = {
'profile_image': profile_image,
'banner_image': banner_image
}
response = self.client.patch(url, data, format='multipart')
Later on when doing a GET to the biz_profile, I verify that response.data['profile_image'] is
But at the same time I get HTTP 400 with "the submitted file is empty" when running the following test:
biz_profile_url = reverse('url_to_reverse_here', args=[
biz_profile.pk])
photo = open('valid_photo.jpg', 'rb')
data = {
'biz_profile': biz_profile_url,
'description': 'a description goes here',
'photo': banner_image
}
Am I doing something wrong? Thanks in advance.