[Django]-'Image' object has no attribute '_committed'

8👍

image = models.FileField() only takes Fileupload object and you are passing image object .

def image_resize(self, field):

    if field:
        image = Img.open(field)
        image = image.convert('RGB')
        image = image.resize((800, 800), Img.ANTIALIAS)
        output = io.BytesIO()
        image.save(output, format='JPEG', quality=85)
        output.seek(0)
        return InMemoryUploadedFile(output, 'ImageField',
                                    field.name,
                                    'image/jpeg',
                                    sys.getsizeof(output), None)
    else:
        return None

InMemoryUploadedFile available in django.core.files.uploadedfile . convert the image in fileupload object

Leave a comment