Skip to content

Instantly share code, notes, and snippets.

@codekoala
Created June 23, 2010 16:55
Show Gist options
  • Select an option

  • Save codekoala/450194 to your computer and use it in GitHub Desktop.

Select an option

Save codekoala/450194 to your computer and use it in GitHub Desktop.
import os
from django.core.signals import post_delete
from articles.models import Attachment
def cleanup_filesystem(sender, instance):
"""Removes attached files from the filesystem"""
try:
os.unlink(instance.attachment.path)
except OSError:
# file doesn't exist or permissions are incorrect
pass
post_delete.connect(cleanup_filesystem, sender=Attachment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment