django-validation-lifecycle 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. django_validation_lifecycle-0.1.0/.github/workflows/docs.yml +31 -0
  2. django_validation_lifecycle-0.1.0/.gitignore +12 -0
  3. django_validation_lifecycle-0.1.0/.python-version +1 -0
  4. django_validation_lifecycle-0.1.0/LICENSE +21 -0
  5. django_validation_lifecycle-0.1.0/PKG-INFO +98 -0
  6. django_validation_lifecycle-0.1.0/README.md +67 -0
  7. django_validation_lifecycle-0.1.0/docs/api/checks.md +3 -0
  8. django_validation_lifecycle-0.1.0/docs/api/conf.md +3 -0
  9. django_validation_lifecycle-0.1.0/docs/api/decorators.md +3 -0
  10. django_validation_lifecycle-0.1.0/docs/api/mixins.md +3 -0
  11. django_validation_lifecycle-0.1.0/docs/api/registry.md +3 -0
  12. django_validation_lifecycle-0.1.0/docs/changelog.md +5 -0
  13. django_validation_lifecycle-0.1.0/docs/guide/checks.md +26 -0
  14. django_validation_lifecycle-0.1.0/docs/guide/configuration.md +22 -0
  15. django_validation_lifecycle-0.1.0/docs/guide/decorators.md +97 -0
  16. django_validation_lifecycle-0.1.0/docs/guide/management-commands.md +33 -0
  17. django_validation_lifecycle-0.1.0/docs/guide/mixins.md +44 -0
  18. django_validation_lifecycle-0.1.0/docs/index.md +52 -0
  19. django_validation_lifecycle-0.1.0/docs/quickstart.md +63 -0
  20. django_validation_lifecycle-0.1.0/mkdocs.yml +74 -0
  21. django_validation_lifecycle-0.1.0/pyproject.toml +52 -0
  22. django_validation_lifecycle-0.1.0/site/404.html +780 -0
  23. django_validation_lifecycle-0.1.0/site/api/checks/index.html +1279 -0
  24. django_validation_lifecycle-0.1.0/site/api/conf/index.html +1025 -0
  25. django_validation_lifecycle-0.1.0/site/api/decorators/index.html +1393 -0
  26. django_validation_lifecycle-0.1.0/site/api/mixins/index.html +2083 -0
  27. django_validation_lifecycle-0.1.0/site/api/registry/index.html +1026 -0
  28. django_validation_lifecycle-0.1.0/site/assets/images/favicon.png +0 -0
  29. django_validation_lifecycle-0.1.0/site/assets/javascripts/LICENSE +29 -0
  30. django_validation_lifecycle-0.1.0/site/assets/javascripts/bundle.ef37db6d.min.js +10 -0
  31. django_validation_lifecycle-0.1.0/site/assets/javascripts/git-revision-date-localized.592bf61f.min.js +1 -0
  32. django_validation_lifecycle-0.1.0/site/assets/javascripts/workers/search.719e0d91.min.js +1 -0
  33. django_validation_lifecycle-0.1.0/site/assets/stylesheets/classic/main.0006804e.min.css +6 -0
  34. django_validation_lifecycle-0.1.0/site/assets/stylesheets/classic/palette.813d4b3f.min.css +4 -0
  35. django_validation_lifecycle-0.1.0/site/assets/stylesheets/git-revision-date-localized.50f6a369.min.css +1 -0
  36. django_validation_lifecycle-0.1.0/site/assets/stylesheets/modern/main.5cb9f1ba.min.css +6 -0
  37. django_validation_lifecycle-0.1.0/site/assets/stylesheets/modern/palette.b60ce83d.min.css +4 -0
  38. django_validation_lifecycle-0.1.0/site/changelog/index.html +866 -0
  39. django_validation_lifecycle-0.1.0/site/guide/checks/index.html +934 -0
  40. django_validation_lifecycle-0.1.0/site/guide/configuration/index.html +904 -0
  41. django_validation_lifecycle-0.1.0/site/guide/decorators/index.html +1008 -0
  42. django_validation_lifecycle-0.1.0/site/guide/management-commands/index.html +895 -0
  43. django_validation_lifecycle-0.1.0/site/guide/mixins/index.html +912 -0
  44. django_validation_lifecycle-0.1.0/site/index.html +925 -0
  45. django_validation_lifecycle-0.1.0/site/objects.inv +0 -0
  46. django_validation_lifecycle-0.1.0/site/quickstart/index.html +963 -0
  47. django_validation_lifecycle-0.1.0/site/search.json +1 -0
  48. django_validation_lifecycle-0.1.0/site/sitemap.xml +42 -0
  49. django_validation_lifecycle-0.1.0/src/validation_lifecycle/__init__.py +14 -0
  50. django_validation_lifecycle-0.1.0/src/validation_lifecycle/apps.py +16 -0
  51. django_validation_lifecycle-0.1.0/src/validation_lifecycle/checks.py +260 -0
  52. django_validation_lifecycle-0.1.0/src/validation_lifecycle/conf.py +47 -0
  53. django_validation_lifecycle-0.1.0/src/validation_lifecycle/contrib/__init__.py +0 -0
  54. django_validation_lifecycle-0.1.0/src/validation_lifecycle/contrib/createsuperuser.py +21 -0
  55. django_validation_lifecycle-0.1.0/src/validation_lifecycle/decorators.py +108 -0
  56. django_validation_lifecycle-0.1.0/src/validation_lifecycle/management/__init__.py +0 -0
  57. django_validation_lifecycle-0.1.0/src/validation_lifecycle/management/commands/__init__.py +0 -0
  58. django_validation_lifecycle-0.1.0/src/validation_lifecycle/management/commands/vl_check.py +98 -0
  59. django_validation_lifecycle-0.1.0/src/validation_lifecycle/migrations/__init__.py +0 -0
  60. django_validation_lifecycle-0.1.0/src/validation_lifecycle/mixins.py +369 -0
  61. django_validation_lifecycle-0.1.0/src/validation_lifecycle/registry.py +37 -0
  62. django_validation_lifecycle-0.1.0/tests/__init__.py +0 -0
  63. django_validation_lifecycle-0.1.0/tests/conftest.py +0 -0
  64. django_validation_lifecycle-0.1.0/tests/settings.py +25 -0
  65. django_validation_lifecycle-0.1.0/tests/test_afull_clean.py +45 -0
  66. django_validation_lifecycle-0.1.0/tests/test_app/__init__.py +0 -0
  67. django_validation_lifecycle-0.1.0/tests/test_app/apps.py +7 -0
  68. django_validation_lifecycle-0.1.0/tests/test_app/models.py +141 -0
  69. django_validation_lifecycle-0.1.0/tests/test_auto_fields.py +24 -0
  70. django_validation_lifecycle-0.1.0/tests/test_checks.py +89 -0
  71. django_validation_lifecycle-0.1.0/tests/test_has_changed.py +76 -0
  72. django_validation_lifecycle-0.1.0/tests/test_registry.py +18 -0
  73. django_validation_lifecycle-0.1.0/uv.lock +710 -0
@@ -0,0 +1,31 @@
1
+ name: Deploy docs
2
+ on:
3
+ push:
4
+ branches: [main]
5
+
6
+ permissions:
7
+ contents: read
8
+ pages: write
9
+ id-token: write
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: astral-sh/setup-uv@v5
17
+ - run: uv sync --extra docs
18
+ - run: uv run zensical build --strict
19
+ - uses: actions/upload-pages-artifact@v3
20
+ with:
21
+ path: site/
22
+
23
+ deploy:
24
+ needs: build
25
+ runs-on: ubuntu-latest
26
+ environment:
27
+ name: github-pages
28
+ url: ${{ steps.deployment.outputs.page_url }}
29
+ steps:
30
+ - id: deployment
31
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,12 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ site/ ← MkDocs build output
8
+ .cache/
9
+ .pytest_cache/
10
+ .ruff_cache/
11
+ .coverage
12
+ htmlcov/
@@ -0,0 +1 @@
1
+ 3.15
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mohamed Nesredin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.5
2
+ Name: django-validation-lifecycle
3
+ Version: 0.1.0
4
+ Summary: Declarative validation rules for Django models.
5
+ Project-URL: Homepage, https://github.com/Mohamed-Kaizen/django-validation-lifecycle
6
+ Project-URL: Source, https://github.com/Mohamed-Kaizen/django-validation-lifecycle
7
+ Author-email: Mohamed Nesredin <mohamednesredin19@hotmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Framework :: Django
12
+ Classifier: Framework :: Django :: 6.0
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.12
20
+ Requires-Dist: django>=6.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
23
+ Requires-Dist: pytest-django>=4.8; extra == 'dev'
24
+ Requires-Dist: pytest-mock>=3.14; extra == 'dev'
25
+ Requires-Dist: pytest>=8; extra == 'dev'
26
+ Provides-Extra: docs
27
+ Requires-Dist: mkdocstrings[python]>=0.27; extra == 'docs'
28
+ Requires-Dist: pymdown-extensions>=10.0; extra == 'docs'
29
+ Requires-Dist: zensical>=0.0.59; extra == 'docs'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # django-validation-lifecycle
33
+
34
+ **Declarative validation rules for Django models.**
35
+
36
+ Stop scattering `clean()` methods and `full_clean()` calls across your
37
+ codebase. Describe rules on the model, get validation in `save()`,
38
+ system checks, and an audit command — for free.
39
+
40
+ ## Install
41
+
42
+ ```bash
43
+ pip install django-validation-lifecycle
44
+ ```
45
+
46
+ Requires Python 3.12+ and Django 6.0+.
47
+
48
+ ## Quick example
49
+
50
+ ```python
51
+ from django.core.exceptions import ValidationError
52
+ from django.db import models
53
+ from validation_lifecycle import AutoValidateModelMixin, validate
54
+
55
+
56
+ class CustomUser(AutoValidateModelMixin):
57
+ username = models.CharField(max_length=100)
58
+ email = models.EmailField()
59
+
60
+ @validate("username", has_changed=True, skip_if_blank=True)
61
+ def username_validate(self) -> None:
62
+ if self.username.lower() in {"admin", "root"}:
63
+ raise ValidationError("Reserved username.")
64
+
65
+ @validate("email")
66
+ def email_validate(self) -> None:
67
+ if not self.email.endswith("@example.com"):
68
+ raise ValidationError("Must be an @example.com address.")
69
+ ```
70
+
71
+ Add `"validation_lifecycle"` to `INSTALLED_APPS`, and you get:
72
+
73
+ - **Save-time validation** — `CustomUser.objects.create(...)` runs `full_clean()` before writing.
74
+ - **Change-aware rules** — `has_changed=True` skips the rule when the field didn't change.
75
+ - **System checks** — `python manage.py check` catches missing mixins, bad field refs, and async `clean()` traps.
76
+ - **Audit command** — `python manage.py vl_check` scans existing rows against current rules.
77
+ - **Async support** — `async def` rules run under `afull_clean()` / `asave()`.
78
+
79
+ ## Features
80
+
81
+ - **Declarative** — rules live next to the fields they check.
82
+ - **Change-aware** — `has_changed=True` only fires on real changes.
83
+ - **Async-ready** — first-class support for `async def` rules.
84
+ - **Inheritance-friendly** — `@no_validate` removes an inherited rule.
85
+ - **Auditable** — `vl_check` scans existing data against current rules.
86
+ - **Safe by default** — system checks catch the common traps.
87
+
88
+ ## Documentation
89
+
90
+ Full docs at **https://Mohamed-Kaizen.github.io/django-validation-lifecycle/**
91
+
92
+ - [Quickstart](https://Mohamed-Kaizen.github.io/django-validation-lifecycle/quickstart/)
93
+ - [Decorators reference](https://Mohamed-Kaizen.github.io/django-validation-lifecycle/guide/decorators/)
94
+ - [System checks](https://Mohamed-Kaizen.github.io/django-validation-lifecycle/guide/checks/)
95
+
96
+ ## License
97
+
98
+ MIT
@@ -0,0 +1,67 @@
1
+ # django-validation-lifecycle
2
+
3
+ **Declarative validation rules for Django models.**
4
+
5
+ Stop scattering `clean()` methods and `full_clean()` calls across your
6
+ codebase. Describe rules on the model, get validation in `save()`,
7
+ system checks, and an audit command — for free.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install django-validation-lifecycle
13
+ ```
14
+
15
+ Requires Python 3.12+ and Django 6.0+.
16
+
17
+ ## Quick example
18
+
19
+ ```python
20
+ from django.core.exceptions import ValidationError
21
+ from django.db import models
22
+ from validation_lifecycle import AutoValidateModelMixin, validate
23
+
24
+
25
+ class CustomUser(AutoValidateModelMixin):
26
+ username = models.CharField(max_length=100)
27
+ email = models.EmailField()
28
+
29
+ @validate("username", has_changed=True, skip_if_blank=True)
30
+ def username_validate(self) -> None:
31
+ if self.username.lower() in {"admin", "root"}:
32
+ raise ValidationError("Reserved username.")
33
+
34
+ @validate("email")
35
+ def email_validate(self) -> None:
36
+ if not self.email.endswith("@example.com"):
37
+ raise ValidationError("Must be an @example.com address.")
38
+ ```
39
+
40
+ Add `"validation_lifecycle"` to `INSTALLED_APPS`, and you get:
41
+
42
+ - **Save-time validation** — `CustomUser.objects.create(...)` runs `full_clean()` before writing.
43
+ - **Change-aware rules** — `has_changed=True` skips the rule when the field didn't change.
44
+ - **System checks** — `python manage.py check` catches missing mixins, bad field refs, and async `clean()` traps.
45
+ - **Audit command** — `python manage.py vl_check` scans existing rows against current rules.
46
+ - **Async support** — `async def` rules run under `afull_clean()` / `asave()`.
47
+
48
+ ## Features
49
+
50
+ - **Declarative** — rules live next to the fields they check.
51
+ - **Change-aware** — `has_changed=True` only fires on real changes.
52
+ - **Async-ready** — first-class support for `async def` rules.
53
+ - **Inheritance-friendly** — `@no_validate` removes an inherited rule.
54
+ - **Auditable** — `vl_check` scans existing data against current rules.
55
+ - **Safe by default** — system checks catch the common traps.
56
+
57
+ ## Documentation
58
+
59
+ Full docs at **https://Mohamed-Kaizen.github.io/django-validation-lifecycle/**
60
+
61
+ - [Quickstart](https://Mohamed-Kaizen.github.io/django-validation-lifecycle/quickstart/)
62
+ - [Decorators reference](https://Mohamed-Kaizen.github.io/django-validation-lifecycle/guide/decorators/)
63
+ - [System checks](https://Mohamed-Kaizen.github.io/django-validation-lifecycle/guide/checks/)
64
+
65
+ ## License
66
+
67
+ MIT
@@ -0,0 +1,3 @@
1
+ # `validation_lifecycle.checks`
2
+
3
+ ::: validation_lifecycle.checks
@@ -0,0 +1,3 @@
1
+ # `validation_lifecycle.conf`
2
+
3
+ ::: validation_lifecycle.conf
@@ -0,0 +1,3 @@
1
+ # `validation_lifecycle.decorators`
2
+
3
+ ::: validation_lifecycle.decorators
@@ -0,0 +1,3 @@
1
+ # `validation_lifecycle.mixins`
2
+
3
+ ::: validation_lifecycle.mixins
@@ -0,0 +1,3 @@
1
+ # `validation_lifecycle.registry`
2
+
3
+ ::: validation_lifecycle.registry
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Initial release.
@@ -0,0 +1,26 @@
1
+ # System checks
2
+
3
+ `validation_lifecycle` registers Django system checks. Run them with:
4
+
5
+ ```bash
6
+ python manage.py check
7
+ ```
8
+
9
+ | ID | Severity | Trigger |
10
+ |---|---|---|
11
+ | `E001` | Error | `@validate` rule on a model that doesn't inherit the mixin. |
12
+ | `E002` | Error | Rule references a field that doesn't exist. |
13
+ | `E003` | Error | `ValidationModelMixin` placed *after* `models.Model` in MRO. |
14
+ | `E004` | Error | `AutoValidateModelMixin` placed *after* `models.Model` in MRO. |
15
+ | `E005` | Error | `ASYNC_RULES_BEHAVIOR` is not `"skip"` / `"warn"` / `"raise"`. |
16
+ | `E006` | Error | A boolean setting is not a `bool`. |
17
+ | `E007` | Error | `async def clean()` — never awaited by Django. |
18
+ | `E008` | Error | `async def clean_<field>()` — never awaited. |
19
+ | `E009` | Error | `VALIDATION_LIFECYCLE` is not a dict. |
20
+ | `W001` | Warning | Unknown key inside `VALIDATION_LIFECYCLE`. |
21
+
22
+ ## See also
23
+
24
+ - [Configuration](configuration.md) — the settings these checks validate
25
+ - [Decorators](decorators.md) — what triggers `E001` / `E002`
26
+ - [Mixins](mixins.md) — what triggers `E003` / `E004`
@@ -0,0 +1,22 @@
1
+ # Configuration
2
+
3
+ All settings live under `settings.VALIDATION_LIFECYCLE`:
4
+
5
+ ```python
6
+ VALIDATION_LIFECYCLE = {
7
+ "AUTO_VALIDATE_ON_SAVE": True,
8
+ "SYSTEM_CHECKS": True,
9
+ "ASYNC_RULES_BEHAVIOR": "warn",
10
+ }
11
+ ```
12
+
13
+ | Key | Type | Default | Meaning |
14
+ |---|---|---|---|
15
+ | `AUTO_VALIDATE_ON_SAVE` | bool | `True` | Call `full_clean()` inside `save()`. |
16
+ | `SYSTEM_CHECKS` | bool | `True` | Enable `validation_lifecycle.*` system checks. |
17
+ | `ASYNC_RULES_BEHAVIOR` | `"skip"` / `"warn"` / `"raise"` | `"warn"` | What sync `full_clean()` does when async rules exist. |
18
+
19
+ ## Validation errors
20
+
21
+ Unknown keys trigger system warning `W001`. Bad types trigger `E005` /
22
+ `E006` / `E009` — see [System checks](checks.md).
@@ -0,0 +1,97 @@
1
+ # Decorators
2
+
3
+ ## `@validate(...)`
4
+
5
+ Attach a validation rule to a model method.
6
+
7
+ ```python
8
+ @validate(
9
+ *fields,
10
+ order=0,
11
+ has_changed=False,
12
+ when=None,
13
+ was=_UNSET,
14
+ is_now=_UNSET,
15
+ skip_if_blank=False,
16
+ )
17
+ ```
18
+
19
+ ### `fields`
20
+
21
+ Field names the error should be attached to.
22
+
23
+ ```python
24
+ @validate("email")
25
+ def email_ok(self): ...
26
+ ```
27
+
28
+ Rules with no `fields` attach errors to `__all__` (non-field errors).
29
+
30
+ ### `order`
31
+
32
+ Controls **error presentation order** when a field has multiple failures.
33
+ Lower runs first.
34
+
35
+ ```python
36
+ @validate("email", order=10)
37
+ def normalize_first(self): ...
38
+
39
+ @validate("email", order=20)
40
+ def uniqueness(self): ...
41
+ ```
42
+
43
+ ### `has_changed`
44
+
45
+ Run only when at least one of `fields` changed since the last save.
46
+
47
+ ```python
48
+ @validate("email", has_changed=True)
49
+ def email_ok(self): ...
50
+ ```
51
+
52
+ New instances always run. On updates, the snapshot is refreshed after
53
+ `save()` so unchanged fields are skipped on subsequent saves.
54
+
55
+ ### `skip_if_blank`
56
+
57
+ Skip the rule when any of `fields` is `None` or `""`.
58
+
59
+ ```python
60
+ @validate("phone", skip_if_blank=True)
61
+ def phone_ok(self): ...
62
+ ```
63
+
64
+ Requires at least one field.
65
+
66
+ ### `when` / `was` / `is_now`
67
+
68
+ Reserved for state-transition rules. Semantics are not yet stabilized;
69
+ prefer `has_changed` for now.
70
+
71
+ ### Async rules
72
+
73
+ Decorate an `async def` and it becomes an async rule automatically.
74
+
75
+ ```python
76
+ @validate("email")
77
+ async def email_blacklist(self): ...
78
+ ```
79
+
80
+ Async rules run only under `afull_clean()` / `asave()`. Sync `full_clean()`
81
+ skips them according to `VALIDATION_LIFECYCLE["ASYNC_RULES_BEHAVIOR"]`.
82
+
83
+ ## `@no_validate`
84
+
85
+ Remove an inherited rule.
86
+
87
+ ```python
88
+ from validation_lifecycle import no_validate
89
+
90
+
91
+ class Tenant(CustomUser):
92
+ @no_validate
93
+ def username_validate(self): ...
94
+ ```
95
+
96
+ Child classes of `Tenant` inherit the removal unless they re-decorate
97
+ with `@validate`.
@@ -0,0 +1,33 @@
1
+ # Management commands
2
+
3
+ ## `vl_check`
4
+
5
+ Audit existing rows against current `@validate` rules.
6
+
7
+ ```bash
8
+ python manage.py vl_check # all models
9
+ python manage.py vl_check accounts.CustomUser # one model
10
+ python manage.py vl_check --limit=10 # stop after 10 failures
11
+ ```
12
+
13
+ Output:
14
+
15
+ ```
16
+ → accounts.CustomUser
17
+ ✗ pk=42: {'phone_number': ['Not recognized.']}
18
+ ✓ accounts.CustomUser done
19
+ 2 rows checked, 1 failures
20
+ ```
21
+
22
+ `vl_check` first runs system checks and refuses to proceed if any
23
+ `validation_lifecycle.*` error is present. Fix those, then re-run.
24
+
25
+ ## `createsuperuser` (optional)
26
+
27
+ Wrap Django's `createsuperuser` to convert `ValidationError` into a clean
28
+ `CommandError`:
29
+
30
+ ```python
31
+ # accounts/management/commands/createsuperuser.py
32
+ from validation_lifecycle.contrib.createsuperuser import Command # noqa: F401
33
+ ```
@@ -0,0 +1,44 @@
1
+ # Mixins
2
+
3
+ ## `ValidationModelMixin`
4
+
5
+ Runs `@validate` rules inside `full_clean()` and `afull_clean()`.
6
+ Does **not** validate on `save()`.
7
+
8
+ ```python
9
+ class Product(ValidationModelMixin, models.Model):
10
+ ...
11
+ ```
12
+
13
+ Use it when you want validation to happen only when *you* call
14
+ `full_clean()` — e.g. inside a form, serializer, or background job.
15
+
16
+ ## `AutoValidateModelMixin`
17
+
18
+ Everything `ValidationModelMixin` does, plus `full_clean()` inside
19
+ `save()` / `asave()`.
20
+
21
+ ```python
22
+ class Product(AutoValidateModelMixin, models.Model):
23
+ ...
24
+ ```
25
+
26
+ Disable save-time validation globally with:
27
+
28
+ ```python
29
+ VALIDATION_LIFECYCLE = {"AUTO_VALIDATE_ON_SAVE": False}
30
+ ```
31
+
32
+ ## MRO order matters
33
+
34
+ Always put the mixin **before** the model base:
35
+
36
+ ```python
37
+ # ✅ correct
38
+ class Product(AutoValidateModelMixin, models.Model): ...
39
+
40
+ # ❌ wrong — Django's full_clean wins the MRO race
41
+ class Product(models.Model, AutoValidateModelMixin): ...
42
+ ```
43
+
44
+ The wrong form triggers system check `validation_lifecycle.E003` / `E004`.
@@ -0,0 +1,52 @@
1
+ # django-validation-lifecycle
2
+
3
+ **Declarative validation rules for Django models.**
4
+
5
+ Stop scattering `clean()` methods and `full_clean()` calls across your
6
+ codebase. Describe rules on the model, get validation in `save()`,
7
+ system checks, and an audit command — for free.
8
+
9
+ ## What it looks like
10
+
11
+ ```python
12
+ from django.db import models
13
+ from django.core.exceptions import ValidationError
14
+ from validation_lifecycle import AutoValidateModelMixin, validate
15
+
16
+
17
+ class CustomUser(AutoValidateModelMixin):
18
+ username = models.CharField(max_length=100)
19
+ email = models.EmailField()
20
+
21
+ @validate("username", has_changed=True, skip_if_blank=True)
22
+ def username_validate(self) -> None:
23
+ if self.username.lower() in {"admin", "root"}:
24
+ raise ValidationError("Reserved username.")
25
+
26
+ @validate("email")
27
+ def email_validate(self) -> None:
28
+ if not self.email.endswith("@example.com"):
29
+ raise ValidationError("Must be an @example.com address.")
30
+ ```
31
+
32
+ That's it. `CustomUser.objects.create(...)` now validates before writing;
33
+ `python manage.py vl_check` audits existing rows; system checks catch
34
+ misconfigurations at startup.
35
+
36
+ ## Highlights
37
+
38
+ - **Declarative** — rules live next to the fields they check.
39
+ - **Change-aware** — `has_changed=True` skips unchanged fields on save.
40
+ - **Async-ready** — `async def` rules run under `afull_clean()` / `asave()`.
41
+ - **Inheritance-friendly** — `@no_validate` removes an inherited rule.
42
+ - **Auditable** — `vl_check` scans existing rows against current rules.
43
+ - **Safe by default** — system checks catch missing mixins, bad field
44
+ references, and async `clean()` traps.
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ pip install django-validation-lifecycle
50
+ ```
51
+
52
+ Then read the [Quickstart](quickstart.md).
@@ -0,0 +1,63 @@
1
+ # Quickstart
2
+
3
+ ## 1. Install
4
+
5
+ ```bash
6
+ pip install django-validation-lifecycle
7
+ ```
8
+
9
+ ## 2. Add the app
10
+
11
+ ```python
12
+ # settings.py
13
+ INSTALLED_APPS = [
14
+ # ...
15
+ "validation_lifecycle",
16
+ ]
17
+ ```
18
+
19
+ ## 3. Subclass the mixin
20
+
21
+ ```python
22
+ from django.core.exceptions import ValidationError
23
+ from django.db import models
24
+ from validation_lifecycle import AutoValidateModelMixin, validate
25
+
26
+
27
+ class Product(AutoValidateModelMixin):
28
+ name = models.CharField(max_length=100)
29
+ price = models.DecimalField(max_digits=10, decimal_places=2)
30
+
31
+ @validate("price")
32
+ def price_positive(self) -> None:
33
+ if self.price <= 0:
34
+ raise ValidationError("Price must be positive.")
35
+ ```
36
+
37
+ `AutoValidateModelMixin` runs `full_clean()` on every `save()`.
38
+
39
+ If you only want validation inside `full_clean()` (no save-time hook),
40
+ use `ValidationModelMixin` instead.
41
+
42
+ ## 4. Migrate and run
43
+
44
+ ```bash
45
+ python manage.py makemigrations
46
+ python manage.py migrate
47
+ ```
48
+
49
+ ## 5. Audit existing rows (optional)
50
+
51
+ ```bash
52
+ python manage.py vl_check
53
+ ```
54
+
55
+ This walks every model that inherits `ValidationModelMixin` and reports
56
+ rows that fail their current rules.
57
+
58
+ ## Next
59
+
60
+ - [Decorators](guide/decorators.md) — every `@validate(...)` option
61
+ - [Mixins](guide/mixins.md) — `ValidationModelMixin` vs `AutoValidateModelMixin`
62
+ - [Configuration](guide/configuration.md) — `VALIDATION_LIFECYCLE` settings
63
+ - [System checks](guide/checks.md) — error codes and fixes
@@ -0,0 +1,74 @@
1
+ site_name: django-validation-lifecycle
2
+ site_description: Declarative validation rules for Django models.
3
+ site_url: https://github.com/Mohamed-Kaizen/django-validation-lifecycle
4
+ repo_url: https://github.com/Mohamed-Kaizen/django-validation-lifecycle
5
+ repo_name: Mohamed-Kaizen/django-validation-lifecycle
6
+ edit_uri: edit/main/docs/
7
+ site_author: Mohamed Nesredin
8
+ copyright: "&copy; 2026 November"
9
+
10
+ docs_dir: docs
11
+
12
+ theme:
13
+ name: material
14
+ variant: modern
15
+ language: en
16
+ features:
17
+ - navigation.sections
18
+ - navigation.expand
19
+ - navigation.top
20
+ - toc.integrate
21
+ - search.suggest
22
+ - search.highlight
23
+ - content.code.copy
24
+ palette:
25
+ - media: "(prefers-color-scheme: light)"
26
+ scheme: default
27
+ toggle:
28
+ icon: material/brightness-7
29
+ name: Switch to dark mode
30
+ - media: "(prefers-color-scheme: dark)"
31
+ scheme: slate
32
+ toggle:
33
+ icon: material/brightness-4
34
+ name: Switch to light mode
35
+
36
+ plugins:
37
+ - search
38
+ - mkdocstrings:
39
+ handlers:
40
+ python:
41
+ paths: [src]
42
+ options:
43
+ docstring_style: google
44
+ show_source: true
45
+ show_root_heading: true
46
+ show_category_heading: true
47
+ members_order: source
48
+ show_signature_annotations: true
49
+
50
+ nav:
51
+ - Home: index.md
52
+ - Quickstart: quickstart.md
53
+ - Guide:
54
+ - Decorators: guide/decorators.md
55
+ - Mixins: guide/mixins.md
56
+ - Configuration: guide/configuration.md
57
+ - System checks: guide/checks.md
58
+ - Management commands: guide/management-commands.md
59
+ - API Reference:
60
+ - decorators: api/decorators.md
61
+ - mixins: api/mixins.md
62
+ - registry: api/registry.md
63
+ - conf: api/conf.md
64
+ - checks: api/checks.md
65
+ - Changelog: changelog.md
66
+
67
+ markdown_extensions:
68
+ - admonition
69
+ - pymdownx.details
70
+ - pymdownx.superfences
71
+ - pymdownx.tabbed:
72
+ alternate_style: true
73
+ - toc:
74
+ permalink: true