[Django]-Django detecting changed ImageField with same filename

3👍

Add this snippet”

def has_changed(instance, field):
        if not instance.pk:
            return False
        old_value = instance.__class__._default_manager.\
                 filter(pk=instance.pk).values(field).get()[field]
        return not getattr(instance, field) == old_value

then in your save

def save(self, *args, **kwargs):
            if has_changed(self, 'field_here'):

            super(Sneetch, self).save(*args, **kwargs)

Leave a comment