diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0e07550..bc9a569 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,7 +42,7 @@ jobs: - python: "3.10" toxenv: py310-django41 - python: "3.11" - toxenv: py310-django41 + toxenv: py311-django41 - python: "pypy-3.8" toxenv: pypy3-django41 steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index e09d5d8..0a63e73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ## [7.0.0] - TBD ### Added -- Update to run tests for django 4.1. -- Update to run tests on python 3.11 with django 4.1. -- Select mode, with the ability to only cleanup selected models using a `select` decorator. Resolves issue [#75]. +- Run tests for django 4.1. +- Run tests on python 3.11 with django 4.1. +- Select mode, with the ability to only cleanup selected models using a `select` decorator. Resolves issue [#75] for [@daviddavis](https://github.com/daviddavis). +- Documentation on the known limitations of referencing a file by multiple model instances. Resolves issue [#98] for [@Grosskopf](https://github.com/Grosskopf) ## Changed -- Pass more data to the cleanup_pre_delete and cleanup_post_delete signals. Resolves issue [#96]. +- Pass more data to the cleanup_pre_delete and cleanup_post_delete signals. Resolves issue [#96] for [@NadavK](https://github.com/NadavK). ### Removed - Dropped support for django 2.2 and python 3.5. @@ -81,7 +82,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.1.4] - 2012-08-16 ## [0.1.0] - 2012-08-14 -[Unreleased]: https://github.com/un1t/django-cleanup/compare/6.0.0...HEAD +[Unreleased]: https://github.com/un1t/django-cleanup/compare/7.0.0...HEAD [7.0.0]: https://github.com/un1t/django-cleanup/compare/6.0.0...7.0.0 [6.0.0]: https://github.com/un1t/django-cleanup/compare/5.2.0...6.0.0 [5.2.0]: https://github.com/un1t/django-cleanup/compare/5.1.0...5.2.0 @@ -117,6 +118,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [0.1.4]: https://github.com/un1t/django-cleanup/compare/0.1.0...0.1.4 [0.1.0]: https://github.com/un1t/django-cleanup/releases/tag/0.1.0 +[#98]: https://github.com/un1t/django-cleanup/issues/98 [#96]: https://github.com/un1t/django-cleanup/issues/96 [#89]: https://github.com/un1t/django-cleanup/issues/89 [#88]: https://github.com/un1t/django-cleanup/pull/88 @@ -124,5 +126,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#81]: https://github.com/un1t/django-cleanup/pull/81 [#80]: https://github.com/un1t/django-cleanup/pull/80 [#76]: https://github.com/un1t/django-cleanup/pull/76 +[#75]: https://github.com/un1t/django-cleanup/issues/75 [#74]: https://github.com/un1t/django-cleanup/pull/74 [#73]: https://github.com/un1t/django-cleanup/issues/73 diff --git a/README.rst b/README.rst index 724d088..6fea595 100644 --- a/README.rst +++ b/README.rst @@ -25,7 +25,7 @@ whether or not a :code:`FileField`'s value has changed a local cache of original the model instance. If a condition is detected that should result in a file deletion, a function to delete the file is setup and inserted into the commit phase of the current transaction. -**Warning! Please be aware of the Known Limitations documented below!** +**Warning! Please be aware of the known limitations documented below!** Installation ============ @@ -71,10 +71,10 @@ You can check if your ``Model`` is loaded by using from django.apps import apps apps.get_models() -Known Limitations +Known limitations ================= -Database Should Support Transactions +Database should support transactions ------------------------------------ If you are using a database that does not support transactions you may lose files if a transaction will rollback at the right instance. This outcome is mitigated by our use of @@ -87,10 +87,11 @@ concerned about this behavior you will need another solution for old file deleti File referenced by multiple model instances ------------------------------------------- This app is designed with the assumption that each file is referenced only once. If you are sharing -a file over two or more model instances you will not have the desired functionality. If you want to -reference a file from multiple models add a level of indirection. That is, use a separate file model -that is referenced from other models through a foreign key. There are many file management apps -already available in the django ecosystem that fulfill this behavior. +a file over two or more model instances you will not have the desired functionality. Be cautious of +copying model instances, as this will cause a file to be shared by more than one instance. If you +want to reference a file from multiple models add a level of indirection. That is, use a separate +file model that is referenced from other models through a foreign key. There are many file +management apps already available in the django ecosystem that fulfill this behavior. Advanced ======== diff --git a/src/django_cleanup/apps.py b/src/django_cleanup/apps.py index 1a8a709..002965f 100644 --- a/src/django_cleanup/apps.py +++ b/src/django_cleanup/apps.py @@ -12,7 +12,7 @@ class CleanupConfig(AppConfig): default = True def ready(self): - cache.prepare() + cache.prepare(False) handlers.connect() class CleanupSelectedConfig(AppConfig): diff --git a/src/django_cleanup/cache.py b/src/django_cleanup/cache.py index cac857c..a2e3423 100644 --- a/src/django_cleanup/cache.py +++ b/src/django_cleanup/cache.py @@ -24,7 +24,7 @@ def fields_dict_default(): # cache init ## -def prepare(select_mode=False): +def prepare(select_mode): '''Prepare the cache for all models, non-reentrant''' if FIELDS: # pragma: no cover return @@ -121,6 +121,7 @@ def get_mangled_select(model): '''returns a mangled attribute name specific to the model for select functionality''' return '_{opt.model_name}__{opt.app_label}_cleanup_select'.format(opt=model._meta) + # booleans ##