Also listen to post_delete instead of pre_delete when deleting a document

This commit is contained in:
Janneke Janssen 2016-08-30 17:46:26 +02:00 committed by Matt Westcott
parent 722ea1d3d8
commit e0815f7473

View file

@ -6,7 +6,7 @@ from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models.signals import pre_delete
from django.db.models.signals import post_delete
from django.dispatch import Signal
from django.dispatch.dispatcher import receiver
from django.utils.encoding import python_2_unicode_compatible
@ -110,8 +110,8 @@ def get_document_model():
return document_model
# Receive the pre_delete signal and delete the file associated with the model instance.
@receiver(pre_delete, sender=Document)
# Receive the post_delete signal and delete the file associated with the model instance.
@receiver(post_delete, sender=Document)
def document_delete(sender, instance, **kwargs):
# Pass false so FileField doesn't save the model.
instance.file.delete(False)