1👍
✅
Are you sure the Issue is not being deleted? The defaul behavior for the ForeignKey is to cascade the deletion:
ForeignKey.on_delete
When an object referenced by a ForeignKey is deleted, Django by default emulates the behavior of the SQL constraint ON DELETE CASCADE
and also deletes the object containing the ForeignKey. This behavior
can be overridden by specifying the on_delete argument.
Are you using sqlite3? I’m not sure it has cascading enabled by default.
To delete the image, you might want to use the pre_delete
signal:
from django.db.models.signals import pre_save
from django.dispatch import receiver
from myapp.models import Preview
@receiver(pre_delete, sender=Preview)
def delete_image(sender, instance, using):
# delete the image -> instance.previewPath
More info on signals:
https://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.pre_delete
https://docs.djangoproject.com/en/dev/topics/signals/
Source:stackexchange.com