Skip to content

Commit 5994a76

Browse files
authored
Merge pull request #64 from bckohan/1.3.x
1.3.x
2 parents 7c5d162 + 6cc6919 commit 5994a76

File tree

10 files changed

+70
-59
lines changed

10 files changed

+70
-59
lines changed

.github/workflows/test.yml

+17-11
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,29 @@ jobs:
99
matrix:
1010
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
1111
django-version:
12-
- 'Django~=3.2.0' # LTS April 2024
13-
- 'Django~=4.2.0' # LTS April 2026
14-
- 'Django~=5.0.0' # April 2025
12+
- '3.2' # LTS April 2024
13+
- '4.2' # LTS April 2026
14+
- '5.0' # April 2025
15+
- '5.1b1' # December 2025
1516
exclude:
1617
- python-version: '3.7'
17-
django-version: 'Django~=5.0.0'
18+
django-version: '5.0'
1819
- python-version: '3.7'
19-
django-version: 'Django~=4.2.0'
20+
django-version: '4.2'
2021
- python-version: '3.8'
21-
django-version: 'Django~=5.0.0'
22+
django-version: '5.0'
2223
- python-version: '3.9'
23-
django-version: 'Django~=5.0.0'
24+
django-version: '5.0'
2425
- python-version: '3.11'
25-
django-version: 'Django~=3.2.0'
26+
django-version: '3.2'
2627
- python-version: '3.12'
27-
django-version: 'Django~=3.2.0'
28+
django-version: '3.2'
29+
- python-version: '3.7'
30+
django-version: '5.1b1'
31+
- python-version: '3.8'
32+
django-version: '5.1b1'
33+
- python-version: '3.9'
34+
django-version: '5.1b1'
2835

2936
steps:
3037
- uses: actions/checkout@v4
@@ -44,7 +51,7 @@ jobs:
4451
poetry config virtualenvs.in-project true
4552
poetry run pip install --upgrade pip
4653
poetry install
47-
poetry run pip install -U "${{ matrix.django-version }}"
54+
poetry run pip install -U "Django~=${{ matrix.django-version }}"
4855
- name: No Optional Dependency Unit Tests
4956
run: |
5057
poetry run pytest --cov-fail-under=30
@@ -82,7 +89,6 @@ jobs:
8289
poetry run doc8 -q doc
8390
poetry check
8491
poetry run pip check
85-
poetry run safety check --full-report
8692
poetry run python -m readme_renderer ./README.rst -o /tmp/README.html
8793
8894
- name: Upload coverage to Codecov

.safety-policy.yml

-16
This file was deleted.

django_enum/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
'EnumFilter'
4848
]
4949

50-
VERSION = (1, 3, 0)
50+
VERSION = (1, 3, 2)
5151

5252
__title__ = 'Django Enum'
5353
__version__ = '.'.join(str(i) for i in VERSION)
5454
__author__ = 'Brian Kohan'
5555
__license__ = 'MIT'
56-
__copyright__ = 'Copyright 2022-2023 Brian Kohan'
56+
__copyright__ = 'Copyright 2022-2024 Brian Kohan'

django_enum/fields.py

+10
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ def deconstruct(self) -> Tuple[str, str, List, dict]:
181181
if self.enum is not None:
182182
kwargs['choices'] = choices(self.enum)
183183

184+
if 'db_default' in kwargs:
185+
try:
186+
kwargs['db_default'] = getattr(
187+
self.to_python(kwargs['db_default']),
188+
'value',
189+
kwargs['db_default']
190+
)
191+
except ValidationError:
192+
pass
193+
184194
if 'default' in kwargs:
185195
# ensure default in deconstructed fields is always the primitive
186196
# value type

django_enum/tests/db_default/migrations/0001_initial.py

+24-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Generated by Django 5.0 on 2023-12-13 20:24
1+
# Generated by Django 5.0.2 on 2024-03-03 06:40
22

3+
import django.db.models.functions.text
34
import django_enum.fields
4-
import django_enum.tests.djenum.enums
55
from django.db import migrations, models
66

77

@@ -33,7 +33,7 @@ class Migration(migrations.Migration):
3333
(2, "Value 2"),
3434
(32767, "Value 32767"),
3535
],
36-
db_default=models.Value(None),
36+
db_default=None,
3737
null=True,
3838
),
3939
),
@@ -48,7 +48,7 @@ class Migration(migrations.Migration):
4848
(2, "Value 2"),
4949
(32767, "Value 32767"),
5050
],
51-
db_default=models.Value(32767),
51+
db_default=32767,
5252
),
5353
),
5454
(
@@ -61,7 +61,7 @@ class Migration(migrations.Migration):
6161
(2, "Value 2"),
6262
(2147483647, "Value 2147483647"),
6363
],
64-
db_default=models.Value(2147483647),
64+
db_default=2147483647,
6565
),
6666
),
6767
(
@@ -75,7 +75,7 @@ class Migration(migrations.Migration):
7575
(2, "Value 2"),
7676
(2147483647, "Value 2147483647"),
7777
],
78-
db_default=models.Value(-2147483648),
78+
db_default=-2147483648,
7979
null=True,
8080
),
8181
),
@@ -89,7 +89,7 @@ class Migration(migrations.Migration):
8989
(2, "Value 2"),
9090
(2147483648, "Value 2147483648"),
9191
],
92-
db_default=models.Value(None),
92+
db_default=None,
9393
null=True,
9494
),
9595
),
@@ -103,7 +103,7 @@ class Migration(migrations.Migration):
103103
(2, "Value 2"),
104104
(2147483648, "Value 2147483648"),
105105
],
106-
db_default=models.Value(-2147483649),
106+
db_default=-2147483649,
107107
),
108108
),
109109
(
@@ -115,7 +115,7 @@ class Migration(migrations.Migration):
115115
(2.71828, "Euler's Number"),
116116
(1.618033988749895, "Golden Ratio"),
117117
],
118-
db_default=models.Value(1.618033988749895),
118+
db_default=1.618033988749895,
119119
null=True,
120120
),
121121
),
@@ -129,7 +129,7 @@ class Migration(migrations.Migration):
129129
("V333", "Value3"),
130130
("D", "Default"),
131131
],
132-
db_default=models.Value(""),
132+
db_default="",
133133
max_length=4,
134134
),
135135
),
@@ -143,7 +143,9 @@ class Migration(migrations.Migration):
143143
("V333", "Value3"),
144144
("D", "Default"),
145145
],
146-
db_default=models.Value("db_default"),
146+
db_default=django.db.models.functions.text.Concat(
147+
models.Value("db"), models.Value("_default")
148+
),
147149
default="",
148150
max_length=10,
149151
),
@@ -158,22 +160,22 @@ class Migration(migrations.Migration):
158160
("V333", "Value3"),
159161
("D", "Default"),
160162
],
161-
db_default=models.Value("V22"),
163+
db_default="V22",
162164
default="D",
163165
max_length=10,
164166
),
165167
),
166168
(
167169
"char_field",
168170
models.CharField(
169-
blank=True, db_default=models.Value("db_default"), max_length=10
171+
blank=True, db_default="db_default", max_length=10
170172
),
171173
),
172174
(
173175
"doubled_char_field",
174176
models.CharField(
175177
blank=True,
176-
db_default=models.Value("db_default"),
178+
db_default="db_default",
177179
default="default",
178180
max_length=10,
179181
),
@@ -183,24 +185,21 @@ class Migration(migrations.Migration):
183185
django_enum.fields.EnumPositiveSmallIntegerField(
184186
blank=True,
185187
choices=[(1, "ONE"), (2, "TWO"), (3, "THREE")],
186-
db_default=models.Value(
187-
django_enum.tests.djenum.enums.ExternEnum["THREE"]
188-
),
188+
db_default=3,
189189
null=True,
190190
),
191191
),
192192
(
193193
"dj_int_enum",
194194
django_enum.fields.EnumPositiveSmallIntegerField(
195-
choices=[(1, "One"), (2, "Two"), (3, "Three")],
196-
db_default=models.Value(1),
195+
choices=[(1, "One"), (2, "Two"), (3, "Three")], db_default=1
197196
),
198197
),
199198
(
200199
"dj_text_enum",
201200
django_enum.fields.EnumCharField(
202201
choices=[("A", "Label A"), ("B", "Label B"), ("C", "Label C")],
203-
db_default=models.Value("A"),
202+
db_default="A",
204203
max_length=1,
205204
),
206205
),
@@ -213,7 +212,7 @@ class Migration(migrations.Migration):
213212
(2, "Value 2"),
214213
(32767, "Value 32767"),
215214
],
216-
db_default=models.Value(5),
215+
db_default=5,
217216
null=True,
218217
),
219218
),
@@ -227,7 +226,7 @@ class Migration(migrations.Migration):
227226
("V333", "Value3"),
228227
("D", "Default"),
229228
],
230-
db_default=models.Value("arbitrary"),
229+
db_default="arbitrary",
231230
max_length=12,
232231
),
233232
),
@@ -240,7 +239,7 @@ class Migration(migrations.Migration):
240239
(2, "Value 2"),
241240
(32767, "Value 32767"),
242241
],
243-
db_default=models.Value(2),
242+
db_default=2,
244243
null=True,
245244
),
246245
),
@@ -253,7 +252,7 @@ class Migration(migrations.Migration):
253252
(2, "Value 2"),
254253
(32767, "Value 32767"),
255254
],
256-
db_default=models.Value(32767),
255+
db_default=32767,
257256
null=True,
258257
),
259258
),
@@ -266,7 +265,7 @@ class Migration(migrations.Migration):
266265
(2, "Value 2"),
267266
(32767, "Value 32767"),
268267
],
269-
db_default=models.Value(None),
268+
db_default=None,
270269
null=True,
271270
),
272271
),

django_enum/tests/db_default/models.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
SmallPosIntEnum,
1515
TextEnum,
1616
)
17+
from django.db.models.functions import Concat
18+
from django.db.models.expressions import Value
1719

1820

1921
class DBDefaultTester(models.Model):
@@ -30,7 +32,7 @@ class DBDefaultTester(models.Model):
3032
constant = EnumField(Constants, null=True, db_default=Constants.GOLDEN_RATIO, blank=True)
3133

3234
text = EnumField(TextEnum, db_default='', blank=True, strict=False)
33-
doubled_text = EnumField(TextEnum, default='', db_default='db_default', blank=True, max_length=10, strict=False)
35+
doubled_text = EnumField(TextEnum, default='', db_default=Concat(Value('db'), Value('_default')), blank=True, max_length=10, strict=False)
3436
doubled_text_strict = EnumField(TextEnum, default=TextEnum.DEFAULT, db_default=TextEnum.VALUE2, blank=True, max_length=10)
3537

3638
char_field = models.CharField(db_default='db_default', blank=True, max_length=10)

doc/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ sphinxcontrib-htmlhelp==2.0.1; python_version >= "3.5"
66
sphinxcontrib-jsmath==1.0.1; python_version >= "3.5"
77
sphinxcontrib-qthelp==1.0.3; python_version >= "3.5"
88
sphinxcontrib-serializinghtml==1.1.5; python_version >= "3.5"
9-
django-enum==1.3.0
9+
django-enum==1.3.1

doc/source/changelog.rst

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
Change Log
33
==========
44

5+
v1.3.2
6+
======
7+
8+
* Fixed `Support Django 5.1 <https://github.com/bckohan/django-enum/issues/63>`_
9+
10+
v1.3.1
11+
======
12+
13+
* Fixed `db_default produces expressions instead of primitives when given enum value instances. <https://github.com/bckohan/django-enum/issues/59>`_
14+
515
v1.3.0
616
======
717

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-enum"
3-
version = "1.3.0"
3+
version = "1.3.2"
44
description = "Full and natural support for enumerations as Django model fields."
55
authors = ["Brian Kohan <[email protected]>"]
66
license = "MIT"
@@ -19,6 +19,7 @@ classifiers = [
1919
"Framework :: Django :: 4.1",
2020
"Framework :: Django :: 4.2",
2121
"Framework :: Django :: 5.0",
22+
"Framework :: Django :: 5.1",
2223
"Intended Audience :: Developers",
2324
"License :: OSI Approved :: MIT License",
2425
"Natural Language :: English",
@@ -62,7 +63,6 @@ pylint = [
6263
]
6364
sphinx-argparse = "^0.3.0"
6465
deepdiff = ">=5.2.3,<7.0.0"
65-
safety = "^2.0.0"
6666
readme-renderer = ">=34,<38"
6767
pygount = "^1.2.4"
6868
types-PyYAML = "^6.0"

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ addopts =
5050
--cov-report=term-missing:skip-covered
5151
--cov-report=html
5252
--cov-report=xml
53-
--cov-fail-under=100
53+
--cov-fail-under=98
5454
--cov-config=setup.cfg
5555

5656
[coverage:run]

0 commit comments

Comments
 (0)