Repository: charettes/django-seal (language: python)

Issue:
Possibility to use as a mixin?
Would it be possible to use a mixin that could implement the `SealableModel, seal=True` functionality? In particular I'm inheriting from django extensions' `TimeStampedModel` for a few models that I'd like to try django-seal on.

Thanks for maintaining this repo!


Discussion / hints:

Fix patch:
diff --git a/seal/models.py b/seal/models.py
index 0200957..13d83e9 100644
--- a/seal/models.py
+++ b/seal/models.py
@@ -60,9 +60,11 @@ class SealableModel(models.Model):
     would incur a database query into exceptions once sealed.
     """
 
-    def __init_subclass__(cls, seal=None):
+    def __init_subclass__(cls, seal=None, **kwargs):
+        if seal is None:
+            seal = getattr(cls, "_seal_managers", seal)
         cls._seal_managers = seal
-        return super().__init_subclass__()
+        return super().__init_subclass__(**kwargs)
 
     objects = SealableManager()
 


Test patch:
diff --git a/tests/test_models.py b/tests/test_models.py
index 5817961..bb42da2 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -195,7 +195,18 @@ class SealedManagers(SealableModel):
             SealedManagers.as_manager.all()._iterable_class, sealed_iterable_class
         )
 
-        class SealedModel(SealableModel, seal=True):
+        class MixinInitSubclass:
+            def __init_subclass__(cls, foo=None, **kwargs):
+                cls.foo = foo
+                super().__init_subclass__(**kwargs)
+
+        class SealedBaseModel(MixinInitSubclass, SealableModel, foo="bar", seal=True):
+            class Meta:
+                abstract = True
+
+        self.assertEqual(SealedBaseModel.foo, "bar")
+
+        class SealedModel(SealedBaseModel):
             manager = SealableManager(seal=False)
             as_manager = SealableQuerySet.as_manager(seal=False)