bartTC / django-attachments

A generic Django application to attach Files (Attachments) to any model.
BSD 3-Clause "New" or "Revised" License
296 stars 90 forks source link

Remove files from disk if settings.DELETE_ATTACHMENTS_FROM_DISK #44

Closed atodorov closed 6 years ago

atodorov commented 6 years ago

@bartTC please review.

atodorov commented 6 years ago

@bartTC can you check this out? I will write the missing tests but I need some opinion on the general approach in this PR

bartTC commented 6 years ago

@atodorov I think this is fine. I was trying to figure out if this is something we actually have to do, or if the FileField can handle this automatically once it'smodel gets deleted.

atodorov commented 6 years ago

I was trying to figure out if this is something we actually have to do, or if the FileField can handle this automatically once it'smodel gets deleted.

From https://docs.djangoproject.com/en/2.0/ref/models/fields/#django.db.models.fields.files.FieldFile.delete

Note that when a model is deleted, related files are not deleted. If you need to cleanup orphaned files, you’ll need to handle it yourself

It looks like deleting files automatically has been removed in Django 1.3: https://docs.djangoproject.com/en/2.0/releases/1.3/#deleting-a-model-doesn-t-delete-associated-files

I will go ahead and write the missing tests.

bartTC commented 6 years ago

Interesting. Thank you, this is a nice addition!