Skip to content

Commit e40c319

Browse files
authored
fix: Fix issue when using Django EnumIntegerField on Admin (#238)
* fix: Fix issue when using Django EnumIntegerField on Admin * chore: remove python3.4 from .travis.yml config
1 parent b07d934 commit e40c319

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ python:
77
- 3.7
88
- 3.6
99
- 3.5
10-
- 3.4
1110
- 2.7
1211

1312
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors

HISTORY.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ History
77

88
* Add support Django 3.0 (tks @klette).
99
* Drop support for Python 3.4.
10+
* Fix issue when using Django EnumIntegerField on Admin.
1011

1112

1213
0.6.0 (2019-09-05)
@@ -16,7 +17,6 @@ History
1617
* Drop support for Django 1.6, 1.7, 1.8.
1718

1819

19-
2020
0.5.3 (2019-02-06)
2121
------------------
2222

choicesenum/django/fields.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ def contribute_to_class(self, cls, name):
8686
setattr(cls, name, Creator(self, cls))
8787

8888
def to_python(self, value):
89-
return self.enum(value)
89+
if isinstance(value, self.enum):
90+
return value
91+
cleaned_value = super(EnumFieldMixin, self).to_python(value)
92+
return self.enum(cleaned_value)
9093

9194
def from_db_value(self, value, *args, **kwargs):
9295
try:

tests/test_django_fields.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,17 @@ def test_integer_field_should_allow_filters():
242242
assert instance.pk == instance2.pk
243243

244244

245+
def test_field_to_python_should_allow_inherited_conversion():
246+
# given
247+
from tests.app.models import User
248+
249+
# when
250+
user_status = User._meta.get_field('status').to_python('1')
251+
252+
# then
253+
assert user_status.is_pending
254+
255+
245256
@pytest.mark.django_db
246257
def test_handle_select_related_with_no_none_enum_value():
247258
# given

0 commit comments

Comments
 (0)