delete_orphans works only with blank=true
vchrisb opened this issue · 5 comments
currently delete_orphans=True only works in conjunction with blank=True due to https://github.com/codingjoe/django-stdimage/blob/master/stdimage/models.py#L287
delete_orphans should also work with blank=False.
I think it should be sufficient to just remove self.blank from the if statement.
Happy to do a PR for this small change.
Hi @vchrisb,
Thanks for reaching out, and thanks for the PR. Maybe you could elaborate a little more on the use case?
I am not certain if I fully understand the problem yet.
Best,
Joe
A stdimage filed which has set blank = True and delete_orphans=True won't delete the old images if an an image is reassigned via a form, e.g. admin.
I would like to have a mandatory image field, which cleans old images when image is reassigned via admin interface.
Currently the if statement checks for delete_orphans AND blank to be True.
I see, OK. Would you mind including a test for that use case in your patch? If you need any help, please let me know. Best Joe
sure. thx!
@codingjoe I added a new test test_pre_save_delete_callback_update
I also fixed and enhanced the original test_pre_save_delete_callback_new test, as it was testing for the wrong file.