Skip to content

Instantly share code, notes, and snippets.

@wiesson
Created December 30, 2016 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wiesson/3dbe350722077f40d1196e132f27e01c to your computer and use it in GitHub Desktop.
Save wiesson/3dbe350722077f40d1196e132f27e01c to your computer and use it in GitHub Desktop.
from django.db.models import ImageField
from django.dispatch import receiver
from django.db import models
class ResponsiveImageField(ImageField):
def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs):
super(ResponsiveImageField, self).__init__(verbose_name, name, width_field, height_field, **kwargs)
def save(self, *args, **kwargs):
print("#### SAVE METHOD")
super(ResponsiveImageField, self).save(*args, **kwargs)
@receiver(models.signals.pre_delete, sender=ResponsiveImageField)
def delete_files(sender, instance, *args, **kwargs):
print("#### DELETE FILES RECEIVER")
if instance and instance.img:
instance.img.delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment