Skip to content

Commit b2ebc87

Browse files
authored
Merge pull request #63 from mcosti/django4-support
Django 4.1 support
2 parents aedc9c2 + 937a62d commit b2ebc87

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ jobs:
66
strategy:
77
matrix:
88
python-version:
9-
- "3.6"
9+
- "3.8"
1010
- "3.9"
1111
django-version:
1212
- "3.1"
1313
- "3.2"
14+
- "4.0"
15+
- "4.1"
1416

1517
steps:
1618
- uses: actions/checkout@v2

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def read_relative_file(filename):
2626
"Framework :: Django",
2727
"Framework :: Django :: 3.1",
2828
"Framework :: Django :: 3.2",
29+
"Framework :: Django :: 4.0",
30+
"Framework :: Django :: 4.1",
2931
"Intended Audience :: Developers",
3032
"License :: OSI Approved :: BSD License",
3133
"Operating System :: OS Independent",

tox.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
[tox]
33
envlist = {py36,py39}-{dj31}
44
{py36,py39}-{dj32}
5+
{py38,py310}-{dj40}
6+
{py38,py310}-{dj41}
57

68
toxworkdir = {homedir}/.tox-django-typed-models
79

@@ -23,3 +25,5 @@ deps =
2325
pytest-sugar
2426
dj31: Django~=3.1.3
2527
dj32: Django~=3.2.0
28+
dj40: Django~=4.0.0
29+
dj41: Django~=4.1.0

typedmodels/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
from functools import partial
23
import types
34

@@ -436,9 +437,9 @@ def save(self, *args, **kwargs):
436437
raise RuntimeError("Untyped %s cannot be saved." % self.__class__.__name__)
437438
return super(TypedModel, self).save(*args, **kwargs)
438439

439-
def _get_unique_checks(self, exclude=None):
440+
def _get_unique_checks(self, exclude=None, **kwargs):
440441
unique_checks, date_checks = super(TypedModel, self)._get_unique_checks(
441-
exclude=exclude
442+
exclude=exclude, **kwargs
442443
)
443444

444445
for i, (model_class, field_names) in reversed(list(enumerate(unique_checks))):

typedmodels/tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,20 @@ def test_uniqueness_check_on_child(db):
370370
child2.validate_unique()
371371

372372

373+
def test_uniqueness_check_include_meta_constraints(db):
374+
"""Django 4.1 introduces a new required kwarg
375+
django/forms/models.py in validate_unique at line 809
376+
for form in valid_forms:
377+
exclude = form._get_validation_exclusions()
378+
unique_checks, date_checks = form.instance._get_unique_checks(
379+
exclude=exclude,
380+
include_meta_constraints=True,
381+
)
382+
"""
383+
child2 = Child2.objects.create(a="a")
384+
child2._get_unique_checks()
385+
386+
373387
def test_non_nullable_subclass_field_error():
374388
with pytest.raises(FieldError):
375389

0 commit comments

Comments
 (0)