[Solved]-Override save method – 'ImageFile' object has no attribute '_committed'

16👍

self.thumbnail = get_thumbnail(self.original,
                                   '50x50',
                                   crop='center',
                                   quality=99).url

solved my problem ..

👤tuna

0👍

I found a similar error recently, which occurred when updating the contents of an ImageField via the django admin.

The error message was: ‘InMemoryUploadedFile’ object has no attribute ‘_committed’

models.py:

class MyObject(models.Model):
    name = models.CharField(max_length=80, unique=True, db_index=True)
    slug = models.SlugField(max_length=80, unique=True, blank=False)
    some_image = ImageField(upload_to='uploads/some/')
    # ... deleted for brevity

This wasn’t affecting every model, I narrowed it down to this:

admin.py:

class MyObjectAdmin(admin.ModelAdmin):
    # ... 
    def queryset(self, request):
        return super(ShipAdmin, self).queryset(request).only('name', 'slug')

The solution was to either alter the admin queryset like so:

admin.py:

class MyObjectAdmin(admin.ModelAdmin):
    # ... 
    def queryset(self, request):
        return super(MyObjectAdmin, self).queryset(request).only('name', 'slug', 'some_image')

Or just to get rid of it completely, since it wasn’t really needed/relevant any more.

Leave a comment