Skip to content

1.3.x #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@ jobs:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
django-version:
- 'Django~=3.2.0' # LTS April 2024
- 'Django~=4.2.0' # LTS April 2026
- 'Django~=5.0.0' # April 2025
- '3.2' # LTS April 2024
- '4.2' # LTS April 2026
- '5.0' # April 2025
- '5.1b1' # December 2025
exclude:
- python-version: '3.7'
django-version: 'Django~=5.0.0'
django-version: '5.0'
- python-version: '3.7'
django-version: 'Django~=4.2.0'
django-version: '4.2'
- python-version: '3.8'
django-version: 'Django~=5.0.0'
django-version: '5.0'
- python-version: '3.9'
django-version: 'Django~=5.0.0'
django-version: '5.0'
- python-version: '3.11'
django-version: 'Django~=3.2.0'
django-version: '3.2'
- python-version: '3.12'
django-version: 'Django~=3.2.0'
django-version: '3.2'
- python-version: '3.7'
django-version: '5.1b1'
- python-version: '3.8'
django-version: '5.1b1'
- python-version: '3.9'
django-version: '5.1b1'

steps:
- uses: actions/checkout@v4
Expand All @@ -44,7 +51,7 @@ jobs:
poetry config virtualenvs.in-project true
poetry run pip install --upgrade pip
poetry install
poetry run pip install -U "${{ matrix.django-version }}"
poetry run pip install -U "Django~=${{ matrix.django-version }}"
- name: No Optional Dependency Unit Tests
run: |
poetry run pytest --cov-fail-under=30
Expand Down Expand Up @@ -82,7 +89,6 @@ jobs:
poetry run doc8 -q doc
poetry check
poetry run pip check
poetry run safety check --full-report
poetry run python -m readme_renderer ./README.rst -o /tmp/README.html

- name: Upload coverage to Codecov
Expand Down
16 changes: 0 additions & 16 deletions .safety-policy.yml

This file was deleted.

4 changes: 2 additions & 2 deletions django_enum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
'EnumFilter'
]

VERSION = (1, 3, 0)
VERSION = (1, 3, 2)

__title__ = 'Django Enum'
__version__ = '.'.join(str(i) for i in VERSION)
__author__ = 'Brian Kohan'
__license__ = 'MIT'
__copyright__ = 'Copyright 2022-2023 Brian Kohan'
__copyright__ = 'Copyright 2022-2024 Brian Kohan'
10 changes: 10 additions & 0 deletions django_enum/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ def deconstruct(self) -> Tuple[str, str, List, dict]:
if self.enum is not None:
kwargs['choices'] = choices(self.enum)

if 'db_default' in kwargs:
try:
kwargs['db_default'] = getattr(
self.to_python(kwargs['db_default']),
'value',
kwargs['db_default']
)
except ValidationError:
pass

if 'default' in kwargs:
# ensure default in deconstructed fields is always the primitive
# value type
Expand Down
49 changes: 24 additions & 25 deletions django_enum/tests/db_default/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 5.0 on 2023-12-13 20:24
# Generated by Django 5.0.2 on 2024-03-03 06:40

import django.db.models.functions.text
import django_enum.fields
import django_enum.tests.djenum.enums
from django.db import migrations, models


Expand Down Expand Up @@ -33,7 +33,7 @@ class Migration(migrations.Migration):
(2, "Value 2"),
(32767, "Value 32767"),
],
db_default=models.Value(None),
db_default=None,
null=True,
),
),
Expand All @@ -48,7 +48,7 @@ class Migration(migrations.Migration):
(2, "Value 2"),
(32767, "Value 32767"),
],
db_default=models.Value(32767),
db_default=32767,
),
),
(
Expand All @@ -61,7 +61,7 @@ class Migration(migrations.Migration):
(2, "Value 2"),
(2147483647, "Value 2147483647"),
],
db_default=models.Value(2147483647),
db_default=2147483647,
),
),
(
Expand All @@ -75,7 +75,7 @@ class Migration(migrations.Migration):
(2, "Value 2"),
(2147483647, "Value 2147483647"),
],
db_default=models.Value(-2147483648),
db_default=-2147483648,
null=True,
),
),
Expand All @@ -89,7 +89,7 @@ class Migration(migrations.Migration):
(2, "Value 2"),
(2147483648, "Value 2147483648"),
],
db_default=models.Value(None),
db_default=None,
null=True,
),
),
Expand All @@ -103,7 +103,7 @@ class Migration(migrations.Migration):
(2, "Value 2"),
(2147483648, "Value 2147483648"),
],
db_default=models.Value(-2147483649),
db_default=-2147483649,
),
),
(
Expand All @@ -115,7 +115,7 @@ class Migration(migrations.Migration):
(2.71828, "Euler's Number"),
(1.618033988749895, "Golden Ratio"),
],
db_default=models.Value(1.618033988749895),
db_default=1.618033988749895,
null=True,
),
),
Expand All @@ -129,7 +129,7 @@ class Migration(migrations.Migration):
("V333", "Value3"),
("D", "Default"),
],
db_default=models.Value(""),
db_default="",
max_length=4,
),
),
Expand All @@ -143,7 +143,9 @@ class Migration(migrations.Migration):
("V333", "Value3"),
("D", "Default"),
],
db_default=models.Value("db_default"),
db_default=django.db.models.functions.text.Concat(
models.Value("db"), models.Value("_default")
),
default="",
max_length=10,
),
Expand All @@ -158,22 +160,22 @@ class Migration(migrations.Migration):
("V333", "Value3"),
("D", "Default"),
],
db_default=models.Value("V22"),
db_default="V22",
default="D",
max_length=10,
),
),
(
"char_field",
models.CharField(
blank=True, db_default=models.Value("db_default"), max_length=10
blank=True, db_default="db_default", max_length=10
),
),
(
"doubled_char_field",
models.CharField(
blank=True,
db_default=models.Value("db_default"),
db_default="db_default",
default="default",
max_length=10,
),
Expand All @@ -183,24 +185,21 @@ class Migration(migrations.Migration):
django_enum.fields.EnumPositiveSmallIntegerField(
blank=True,
choices=[(1, "ONE"), (2, "TWO"), (3, "THREE")],
db_default=models.Value(
django_enum.tests.djenum.enums.ExternEnum["THREE"]
),
db_default=3,
null=True,
),
),
(
"dj_int_enum",
django_enum.fields.EnumPositiveSmallIntegerField(
choices=[(1, "One"), (2, "Two"), (3, "Three")],
db_default=models.Value(1),
choices=[(1, "One"), (2, "Two"), (3, "Three")], db_default=1
),
),
(
"dj_text_enum",
django_enum.fields.EnumCharField(
choices=[("A", "Label A"), ("B", "Label B"), ("C", "Label C")],
db_default=models.Value("A"),
db_default="A",
max_length=1,
),
),
Expand All @@ -213,7 +212,7 @@ class Migration(migrations.Migration):
(2, "Value 2"),
(32767, "Value 32767"),
],
db_default=models.Value(5),
db_default=5,
null=True,
),
),
Expand All @@ -227,7 +226,7 @@ class Migration(migrations.Migration):
("V333", "Value3"),
("D", "Default"),
],
db_default=models.Value("arbitrary"),
db_default="arbitrary",
max_length=12,
),
),
Expand All @@ -240,7 +239,7 @@ class Migration(migrations.Migration):
(2, "Value 2"),
(32767, "Value 32767"),
],
db_default=models.Value(2),
db_default=2,
null=True,
),
),
Expand All @@ -253,7 +252,7 @@ class Migration(migrations.Migration):
(2, "Value 2"),
(32767, "Value 32767"),
],
db_default=models.Value(32767),
db_default=32767,
null=True,
),
),
Expand All @@ -266,7 +265,7 @@ class Migration(migrations.Migration):
(2, "Value 2"),
(32767, "Value 32767"),
],
db_default=models.Value(None),
db_default=None,
null=True,
),
),
Expand Down
4 changes: 3 additions & 1 deletion django_enum/tests/db_default/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
SmallPosIntEnum,
TextEnum,
)
from django.db.models.functions import Concat
from django.db.models.expressions import Value


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

text = EnumField(TextEnum, db_default='', blank=True, strict=False)
doubled_text = EnumField(TextEnum, default='', db_default='db_default', blank=True, max_length=10, strict=False)
doubled_text = EnumField(TextEnum, default='', db_default=Concat(Value('db'), Value('_default')), blank=True, max_length=10, strict=False)
doubled_text_strict = EnumField(TextEnum, default=TextEnum.DEFAULT, db_default=TextEnum.VALUE2, blank=True, max_length=10)

char_field = models.CharField(db_default='db_default', blank=True, max_length=10)
Expand Down
2 changes: 1 addition & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ sphinxcontrib-htmlhelp==2.0.1; python_version >= "3.5"
sphinxcontrib-jsmath==1.0.1; python_version >= "3.5"
sphinxcontrib-qthelp==1.0.3; python_version >= "3.5"
sphinxcontrib-serializinghtml==1.1.5; python_version >= "3.5"
django-enum==1.3.0
django-enum==1.3.1
10 changes: 10 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
Change Log
==========

v1.3.2
======

* Fixed `Support Django 5.1 <https://github.com/bckohan/django-enum/issues/63>`_

v1.3.1
======

* Fixed `db_default produces expressions instead of primitives when given enum value instances. <https://github.com/bckohan/django-enum/issues/59>`_

v1.3.0
======

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-enum"
version = "1.3.0"
version = "1.3.2"
description = "Full and natural support for enumerations as Django model fields."
authors = ["Brian Kohan <[email protected]>"]
license = "MIT"
Expand All @@ -19,6 +19,7 @@ classifiers = [
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Django :: 5.1",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
Expand Down Expand Up @@ -62,7 +63,6 @@ pylint = [
]
sphinx-argparse = "^0.3.0"
deepdiff = ">=5.2.3,<7.0.0"
safety = "^2.0.0"
readme-renderer = ">=34,<38"
pygount = "^1.2.4"
types-PyYAML = "^6.0"
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ addopts =
--cov-report=term-missing:skip-covered
--cov-report=html
--cov-report=xml
--cov-fail-under=100
--cov-fail-under=98
--cov-config=setup.cfg

[coverage:run]
Expand Down
Loading