un1t / django-cleanup

Automatically deletes old file for FileField and ImageField. It also deletes files on models instance deletion.
MIT License
1.11k stars 79 forks source link

Documentation needs improvement. #33

Closed styvane closed 7 years ago

styvane commented 8 years ago

Hello Ilya!

For example if I have a model that look like this:

class Profile(models.Model):
    name = models.CharField(max_length=40)
    doc = models.FieldField(upload_to='folder')

The documentation doesn't say how one should use the signals an not every projects need sorl-thumbnail

un1t commented 8 years ago

Hi! You don't need to use signals in this case.

styvane commented 8 years ago

What I did is simply call os.remove(kwargs['file']) in my callback.

vinnyrose commented 8 years ago

The purpose of signals is to interact with third-party API's. If you don't need to interact with third parties then you don't need to use the signal interface. This library will handle the deletion of files for you (using django's File object API), you don't need to call os.remove yourself.

styvane commented 8 years ago

@vinnyrose Hi, that is what I want but I can see that the test app explicitly deleted the file in the callback passed to the signal.

Can you then please tell me how I should use the signal if my model looks like the example above?

vinnyrose commented 8 years ago

For the model above, you don't need to use signals.

The code you are referencing in the test app is not explicitly deleting the file, it is calling an API function (delete) provided by sorl_thumbnail which deletes thumbnail files (related to but separate from the original file) and clears caches used internal in the sorl_thumbnail app.

The actual deletion of the original file happens here.

For most developers, including yourself, you simple pip install django-cleanup then add django_cleanup to INSTALLED_APPS and it will work as specified.

styvane commented 8 years ago

@vinnyrose Oh that is it :smile:Thank you!

yo1995 commented 5 years ago

Hi! You don't need to use signals in this case.

Maybe you can mention this in README, so that people will know for native app, it doesn't need to add any extra code to use this module.

Also, thanks for the super easy-to-use module! 😄

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.