Skip to content

Commit 3b386c8

Browse files
committed
close #37
1 parent 03def30 commit 3b386c8

File tree

9 files changed

+72
-34
lines changed

9 files changed

+72
-34
lines changed

django_enum/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
'EnumFilter'
4848
]
4949

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

5252
__title__ = 'Django Enum'
5353
__version__ = '.'.join(str(i) for i in VERSION)

django_enum/tests/djenum/admin.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
from django.contrib import admin
2-
from django_enum.tests.djenum.models import EnumTester
2+
from django_enum.tests.djenum.models import EnumTester, AdminDisplayBug35
33

44
admin.site.register(EnumTester)
5+
6+
7+
class AdminDisplayBug35Admin(admin.ModelAdmin):
8+
9+
list_display = ('text_enum', 'int_enum')
10+
readonly_fields = ('text_enum', 'int_enum')
11+
12+
13+
admin.site.register(AdminDisplayBug35, AdminDisplayBug35Admin)

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Generated by Django 3.2.18 on 2023-04-02 18:58
1+
# Generated by Django 3.2.18 on 2023-04-09 00:14
22

3-
import django_enum.fields
43
from django.db import migrations, models
4+
import django_enum.fields
55

66

77
class Migration(migrations.Migration):
@@ -12,6 +12,14 @@ class Migration(migrations.Migration):
1212
]
1313

1414
operations = [
15+
migrations.CreateModel(
16+
name='AdminDisplayBug35',
17+
fields=[
18+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19+
('text_enum', django_enum.fields.EnumCharField(choices=[('A', 'Label A'), ('B', 'Label B'), ('C', 'Label C')], default=None, max_length=1, null=True)),
20+
('int_enum', django_enum.fields.EnumPositiveSmallIntegerField(choices=[(1, 'One'), (2, 'Two'), (3, 'Three')], default=None, null=True)),
21+
],
22+
),
1523
migrations.CreateModel(
1624
name='BadDefault',
1725
fields=[

django_enum/tests/djenum/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,19 @@ class BadDefault(models.Model):
114114
default=5,
115115
blank=True
116116
)
117+
118+
119+
class AdminDisplayBug35(models.Model):
120+
121+
text_enum = EnumField(
122+
DJTextEnum,
123+
null=True,
124+
default=None
125+
)
126+
127+
int_enum = EnumField(
128+
DJIntEnum,
129+
null=True,
130+
default=None
131+
)
132+

django_enum/tests/examples/models.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@ class Map(models.Model):
88
class MapBoxStyle(
99
IntegerChoices,
1010
s('slug', case_fold=True),
11-
s('label', case_fold=True),
1211
p('version')
1312
):
1413
"""
1514
https://docs.mapbox.com/api/maps/styles/
1615
"""
17-
_symmetric_builtins_ = ['name', 'uri']
18-
19-
# name value slug label version
20-
STREETS = 1, 'streets', 'Streets', 11
21-
OUTDOORS = 2, 'outdoors', 'Outdoors', 11
22-
LIGHT = 3, 'light', 'Light', 10
23-
DARK = 4, 'dark', 'Dark', 10
24-
SATELLITE = 5, 'satellite', 'Satellite', 9
25-
SATELLITE_STREETS = 6, 'satellite-streets', 'Satellite Streets', 11
26-
NAVIGATION_DAY = 7, 'navigation-day', 'Navigation Day', 1
27-
NAVIGATION_NIGHT = 8, 'navigation-night', 'Navigation Night', 1
16+
_symmetric_builtins_ = ['name', s('label', case_fold=True), 'uri']
17+
18+
# name value label slug version
19+
STREETS = 1, 'Streets', 'streets', 11
20+
OUTDOORS = 2, 'Outdoors', 'outdoors', 11
21+
LIGHT = 3, 'Light', 'light', 10
22+
DARK = 4, 'Dark', 'dark', 10
23+
SATELLITE = 5, 'Satellite', 'satellite', 9
24+
SATELLITE_STREETS = 6, 'Satellite Streets', 'satellite-streets', 11
25+
NAVIGATION_DAY = 7, 'Navigation Day', 'navigation-day', 1
26+
NAVIGATION_NIGHT = 8, 'Navigation Night', 'navigation-night', 1
2827

2928
@property
3029
def uri(self):

doc/requirements.txt

Lines changed: 1 addition & 1 deletion
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.2.0
9+
django-enum==1.2.1

doc/source/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Change Log
33
==========
44

5+
v1.2.1
6+
======
7+
8+
* Fixed `Document that with version 1.4 of enum-properties label is no longer overridable for Choices <https://github.com/bckohan/django-enum/issues/37>`_
9+
510
v1.2.0
611
======
712

doc/source/examples.rst

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ versioned and that when used as a parameter in the mapbox API they are in a URI
2121
format that is overly verbose for a human friendly user interface.
2222

2323
Each mapbox style enumeration is therefore composed of 4 primary properties. A
24-
name slug used in the URI, a human friendly label for the style, a version
24+
a human friendly label for the style, a name slug used in the URI, a version
2525
number for the style and the full URI specification of the style. We might
2626
implement our style enumeration like so:
2727

@@ -36,23 +36,22 @@ implement our style enumeration like so:
3636
class MapBoxStyle(
3737
IntegerChoices,
3838
s('slug', case_fold=True),
39-
s('label', case_fold=True),
4039
p('version')
4140
):
4241
"""
4342
https://docs.mapbox.com/api/maps/styles/
4443
"""
45-
_symmetric_builtins_ = ['name', 'uri']
46-
47-
# name value slug label version
48-
STREETS = 1, 'streets', 'Streets', 11
49-
OUTDOORS = 2, 'outdoors', 'Outdoors', 11
50-
LIGHT = 3, 'light', 'Light', 10
51-
DARK = 4, 'dark', 'Dark', 10
52-
SATELLITE = 5, 'satellite', 'Satellite', 9
53-
SATELLITE_STREETS = 6, 'satellite-streets', 'Satellite Streets', 11
54-
NAVIGATION_DAY = 7, 'navigation-day', 'Navigation Day', 1
55-
NAVIGATION_NIGHT = 8, 'navigation-night', 'Navigation Night', 1
44+
_symmetric_builtins_ = ['name', 'uri', 'label']
45+
46+
# name value label slug version
47+
STREETS = 1, 'Streets', 'streets', 11
48+
OUTDOORS = 2, 'Outdoors', 'outdoors', 11
49+
LIGHT = 3, 'Light', 'light', 10
50+
DARK = 4, 'Dark', 'dark', 10
51+
SATELLITE = 5, 'Satellite', 'satellite', 9
52+
SATELLITE_STREETS = 6, 'Satellite Streets', 'satellite-streets', 11
53+
NAVIGATION_DAY = 7, 'Navigation Day', 'navigation-day', 1
54+
NAVIGATION_NIGHT = 8, 'Navigation Night', 'navigation-night', 1
5655
5756
@property
5857
def uri(self):
@@ -65,8 +64,10 @@ implement our style enumeration like so:
6564
6665
6766
We've used a small integer as the value of the enumeration to save storage
68-
space. We've also added a symmetric case insensitive slug and human friendly
69-
label for each style and a non-symmetric version property.
67+
space. We've also added a symmetric case insensitive slug and a non-symmetric
68+
version property. We do not need to specify the label property because we're
69+
inheriting from Django's Choices type which provides a ``label`` property as
70+
the second element in the value tuple.
7071

7172
The version numbers will increment over time, but we're only concerned with the
7273
most recent versions, so we'll increment their values in this enumeration as

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-enum"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
description = "Full and natural support for enumerations as Django model fields."
55
authors = ["Brian Kohan <[email protected]>"]
66
license = "MIT"
@@ -15,7 +15,7 @@ classifiers = [
1515
"Topic :: Software Development :: Libraries :: Python Modules",
1616
"Development Status :: 5 - Production/Stable",
1717
"Framework :: Django :: 3.2",
18-
"Framework :: Django :: 4.1",
18+
"Framework :: Django :: 4.0",
1919
"Framework :: Django :: 4.2",
2020
"Intended Audience :: Developers",
2121
"License :: OSI Approved :: MIT License",

0 commit comments

Comments
 (0)