diff --git a/tests/managers.py b/tests/managers.py deleted file mode 100644 index 03ea4739..00000000 --- a/tests/managers.py +++ /dev/null @@ -1,13 +0,0 @@ -from model_utils.managers import SoftDeletableManager, SoftDeletableQuerySet - - -class CustomSoftDeleteQuerySet(SoftDeletableQuerySet): - def only_read(self): - return self.filter(is_read=True) - - -class CustomSoftDeleteManager(SoftDeletableManager): - _queryset_class = CustomSoftDeleteQuerySet - - def only_read(self): - return self.get_queryset().only_read() diff --git a/tests/models.py b/tests/models.py index 44f75907..ac65931c 100644 --- a/tests/models.py +++ b/tests/models.py @@ -9,7 +9,13 @@ from model_utils import Choices from model_utils.fields import MonitorField, SplitField, StatusField, UUIDField -from model_utils.managers import InheritanceManager, JoinManager, QueryManager +from model_utils.managers import ( + InheritanceManager, + JoinManager, + QueryManager, + SoftDeletableManager, + SoftDeletableQuerySet, +) from model_utils.models import ( SoftDeletableModel, StatusModel, @@ -19,7 +25,6 @@ ) from model_utils.tracker import FieldTracker, ModelTracker from tests.fields import MutableField -from tests.managers import CustomSoftDeleteManager class InheritanceManagerTestRelated(models.Model): @@ -347,10 +352,15 @@ class SoftDeletable(SoftDeletableModel): all_objects: ClassVar[Manager[SoftDeletable]] = models.Manager() +class CustomSoftDeleteQuerySet(SoftDeletableQuerySet): + def only_read(self): + return self.filter(is_read=True) + + class CustomSoftDelete(SoftDeletableModel): is_read = models.BooleanField(default=False) - objects: ClassVar[CustomSoftDeleteManager[SoftDeletableModel]] = CustomSoftDeleteManager() + available_objects = SoftDeletableManager.from_queryset(CustomSoftDeleteQuerySet)() # type: ignore[misc] class StringyDescriptor: diff --git a/tests/test_managers/test_softdelete_manager.py b/tests/test_managers/test_softdelete_manager.py index db495c4a..aec53576 100644 --- a/tests/test_managers/test_softdelete_manager.py +++ b/tests/test_managers/test_softdelete_manager.py @@ -6,21 +6,21 @@ class CustomSoftDeleteManagerTests(TestCase): def test_custom_manager_empty(self): - qs = CustomSoftDelete.objects.only_read() + qs = CustomSoftDelete.available_objects.only_read() self.assertEqual(qs.count(), 0) def test_custom_qs_empty(self): - qs = CustomSoftDelete.objects.all().only_read() + qs = CustomSoftDelete.available_objects.all().only_read() self.assertEqual(qs.count(), 0) def test_is_read(self): for is_read in [True, False, True, False]: - CustomSoftDelete.objects.create(is_read=is_read) - qs = CustomSoftDelete.objects.only_read() + CustomSoftDelete.available_objects.create(is_read=is_read) + qs = CustomSoftDelete.available_objects.only_read() self.assertEqual(qs.count(), 2) def test_is_read_removed(self): for is_read, is_removed in [(True, True), (True, False), (False, False), (False, True)]: - CustomSoftDelete.objects.create(is_read=is_read, is_removed=is_removed) - qs = CustomSoftDelete.objects.only_read() + CustomSoftDelete.available_objects.create(is_read=is_read, is_removed=is_removed) + qs = CustomSoftDelete.available_objects.only_read() self.assertEqual(qs.count(), 1)