Skip to content

Commit 477ce54

Browse files
committed
Merge branch 'main' into fix-dja-flags
2 parents d92b8c4 + 4a1688d commit 477ce54

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2962
-2141
lines changed

.github/workflows/debug.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
with:
4040
enable-cache: true
4141
- name: Install Just
42-
uses: extractions/setup-just@v2
42+
uses: extractions/setup-just@v3
4343
- name: Install Dependencies
4444
run: |
4545
just setup ${{ steps.sp.outputs.python-path }}

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
with:
5858
enable-cache: true
5959
- name: Install Just
60-
uses: extractions/setup-just@v2
60+
uses: extractions/setup-just@v3
6161
- name: Install Dependencies
6262
run: |
6363
just setup ${{ steps.sp.outputs.python-path }}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
with:
5050
enable-cache: true
5151
- name: Setup Just
52-
uses: extractions/setup-just@v2
52+
uses: extractions/setup-just@v3
5353
- name: Verify Tag
5454
run: |
5555
TAG_NAME=${GITHUB_REF#refs/tags/}

.github/workflows/test.yml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
- '3.2' # LTS April 2024
3636
- '4.2' # LTS April 2026
3737
- '5.1' # December 2025
38+
- '5.2b1'
3839
exclude:
3940
- django-version: '4.2'
4041
postgres-version: '9.6'
@@ -55,8 +56,16 @@ jobs:
5556
- postgres-version: '9.6'
5657
django-version: '5.1'
5758

59+
- postgres-version: '9.6'
60+
django-version: '5.2b1'
61+
62+
- postgres-version: '12'
63+
django-version: '5.2b1'
64+
5865
- python-version: '3.9'
5966
django-version: '5.1'
67+
- python-version: '3.9'
68+
django-version: '5.2b1'
6069
- python-version: '3.13'
6170
django-version: '3.2'
6271
- python-version: '3.13'
@@ -108,11 +117,15 @@ jobs:
108117
with:
109118
enable-cache: true
110119
- name: Setup Just
111-
uses: extractions/setup-just@v2
120+
uses: extractions/setup-just@v3
112121
- name: Install Release Dependencies
113122
run: |
114123
just setup ${{ steps.sp.outputs.python-path }}
115-
just test-lock Django~=${{ matrix.django-version }}.0
124+
if [ "${{ matrix.django-version }}" = "5.2b1" ]; then
125+
just test-lock "Django==${{ matrix.django-version }}"
126+
else
127+
just test-lock "Django~=${{ matrix.django-version }}.0"
128+
fi
116129
- name: Install Emacs
117130
if: ${{ github.event.inputs.debug == 'true' }}
118131
run: |
@@ -169,7 +182,7 @@ jobs:
169182
with:
170183
enable-cache: true
171184
- name: Setup Just
172-
uses: extractions/setup-just@v2
185+
uses: extractions/setup-just@v3
173186
- name: Install Release Dependencies
174187
run: |
175188
just setup ${{ steps.sp.outputs.python-path }}
@@ -276,7 +289,7 @@ jobs:
276289
with:
277290
enable-cache: true
278291
- name: Setup Just
279-
uses: extractions/setup-just@v2
292+
uses: extractions/setup-just@v3
280293
- name: Install Release Dependencies
281294
run: |
282295
just setup ${{ steps.sp.outputs.python-path }}
@@ -380,7 +393,7 @@ jobs:
380393
with:
381394
enable-cache: true
382395
- name: Setup Just
383-
uses: extractions/setup-just@v2
396+
uses: extractions/setup-just@v3
384397
- name: Install Release Dependencies
385398
run: |
386399
just setup ${{ steps.sp.outputs.python-path }}
@@ -480,7 +493,7 @@ jobs:
480493
with:
481494
enable-cache: true
482495
- name: Setup Just
483-
uses: extractions/setup-just@v2
496+
uses: extractions/setup-just@v3
484497
- name: Install Oracle Client
485498
# https://askubuntu.com/questions/1512196/libaio1-on-noble
486499
run: |
@@ -540,7 +553,7 @@ jobs:
540553
with:
541554
enable-cache: true
542555
- name: Setup Just
543-
uses: extractions/setup-just@v2
556+
uses: extractions/setup-just@v3
544557
- name: Install Release Dependencies
545558
run: |
546559
just setup ${{ steps.sp.outputs.python-path }}
@@ -600,7 +613,7 @@ jobs:
600613
with:
601614
enable-cache: true
602615
- name: Setup Just
603-
uses: extractions/setup-just@v2
616+
uses: extractions/setup-just@v3
604617
- name: Install Release Dependencies
605618
run: |
606619
just setup ${{ steps.sp.outputs.python-path }}
@@ -642,7 +655,7 @@ jobs:
642655
with:
643656
enable-cache: true
644657
- name: Setup Just
645-
uses: extractions/setup-just@v2
658+
uses: extractions/setup-just@v3
646659
- name: Install Release Dependencies
647660
run: |
648661
just setup ${{ steps.sp.outputs.python-path }}

README.md

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@
2424

2525
🚨 **See [migration guide](https://django-enum.readthedocs.io/en/latest/changelog.html#migration-1-x-to-2-x) for notes on 1.x to 2.x migration.** 🚨
2626

27-
Full and natural support for [enumerations](https://docs.python.org/3/library/enum.html#enum.Enum) as Django model fields.
27+
Full and natural support for [PEP435](https://peps.python.org/pep-0435) [enumerations](https://docs.python.org/3/library/enum.html#enum.Enum) as [Django](https://www.djangoproject.com) model fields.
2828

29-
Many packages aim to ease usage of Python enumerations as model fields. Most were superseded when Django provided ``TextChoices`` and ``IntegerChoices`` types. The motivation for [django-enum](https://django-enum.readthedocs.io) was to:
29+
Many packages aim to ease usage of Python enumerations as model fields. Most were superseded when Django provided [TextChoices](https://docs.djangoproject.com/en/stable/ref/models/fields/#field-choices-enum-types) and [IntegerChoices](https://docs.djangoproject.com/en/stable/ref/models/fields/#field-choices-enum-types) types. The motivation for [django-enum](https://pypi.org/project/enum-properties) was to:
3030

31-
* Work with any Python PEP 435 Enum including those that do not derive from Django's TextChoices and IntegerChoices.
32-
* Coerce fields to instances of the Enum type by default.
33-
* Allow strict adherence to Enum values to be disabled.
31+
* Work with any [Enum](https://docs.python.org/3/library/enum.html#enum.Enum) including those that do not derive from Django's [TextChoices](https://docs.djangoproject.com/en/stable/ref/models/fields/#field-choices-enum-types) and [IntegerChoices](https://docs.djangoproject.com/en/stable/ref/models/fields/#field-choices-enum-types).
32+
* Coerce fields to instances of the [Enum](https://docs.python.org/3/library/enum.html#enum.Enum) type by default.
33+
* Allow strict adherence to [Enum](https://docs.python.org/3/library/enum.html#enum.Enum) values to be disabled.
3434
* Handle migrations appropriately. (See [migrations](https://django-enum.readthedocs.io/en/latest/usage.html#migrations))
35-
* Integrate as fully as possible with [Django's](https://www.djangoproject.com) existing level of enum support.
36-
* Support [enum-properties](https://pypi.org/project/enum-properties) to enable richer enumeration types. (A less awkward alternative to dataclass enumerations with more features)
35+
* Integrate as fully as possible with Django's [existing level of enum support](https://docs.djangoproject.com/en/stable/ref/models/fields/#field-choices-enum-types).
36+
* Support [enum-properties](https://pypi.org/project/enum-properties) to enable richer enumeration types. (A less awkward alternative to [dataclass enumerations](https://docs.python.org/3/howto/enum.html#enum-dataclass-support) with more features)
3737
* Represent enum fields with the smallest possible column type.
38-
* Support bit mask queries using standard Python Flag enumerations.
38+
* Support [bit field](https://en.wikipedia.org/wiki/Bit_field) queries using standard Python Flag enumerations.
3939
* Be as simple and light-weight an extension to core [Django](https://www.djangoproject.com) as possible.
40-
* Enforce enumeration value consistency at the database level using check constraints by default.
40+
* Enforce enumeration value consistency at the database level using [check constraints](https://docs.djangoproject.com/en/stable/ref/models/constraints) by default.
4141
* (TODO) Support native database enumeration column types when available.
4242

43-
[django-enum](https://django-enum.readthedocs.io) works in concert with [Django's](https://www.djangoproject.com) built in ``TextChoices`` and ``IntegerChoices`` to provide a new model field type, ``EnumField``, that resolves the correct native [Django](https://www.djangoproject.com) field type for the given enumeration based on its value type and range. For example, ``IntegerChoices`` that contain values between 0 and 32767 become [PositiveSmallIntegerField](https://docs.djangoproject.com/en/stable/ref/models/fields/#positivesmallintegerfield).
43+
[django-enum](https://pypi.org/project/enum-properties) provides a new model field type, [EnumField](https://django-enum.rtfd.io/en/stable/reference/fields.html#django_enum.fields.EnumField), that allows you to treat almost any [PEP435](https://peps.python.org/pep-0435) enumeration as a database column. [EnumField](https://django-enum.rtfd.io/en/stable/reference/fields.html#django_enum.fields.EnumField) resolves the correct native [Django](https://www.djangoproject.com) field type for the given enumeration based on its value type and range. For example, [IntegerChoices](https://docs.djangoproject.com/en/stable/ref/models/fields/#field-choices-enum-types) that contain values between 0 and 32767 become [PositiveSmallIntegerField](https://docs.djangoproject.com/en/stable/ref/models/fields/#positivesmallintegerfield).
4444

4545
```python
4646

@@ -70,7 +70,7 @@ Many packages aim to ease usage of Python enumerations as model fields. Most wer
7070
int_enum = EnumField(IntEnum, default=IntEnum.ONE)
7171
```
7272

73-
``EnumField`` **is more than just an alias. The fields are now assignable and accessible as their enumeration type rather than by-value:**
73+
[EnumField](https://django-enum.rtfd.io/en/stable/reference/fields.html#django_enum.fields.EnumField) **is more than just an alias. The fields are now assignable and accessible as their enumeration type rather than by-value:**
7474

7575
```python
7676

@@ -86,9 +86,9 @@ Many packages aim to ease usage of Python enumerations as model fields. Most wer
8686
assert instance.int_enum.value == 3
8787
```
8888

89-
## Flag Support
89+
## Flag Support (BitFields)
9090

91-
[Flag](https://docs.python.org/3/library/enum.html#enum.Flag) types are also seamlessly supported! This allows a database column to behave like a bit mask and is an alternative to multiple boolean columns. There are mostly positive performance implications for using a bit mask instead of booleans depending on the size of the bit mask and the types of queries you will run against it. For bit masks more than a few bits long the size reduction both speeds up queries and reduces the required storage space. See the documentation for [discussion and benchmarks](https://django-enum.readthedocs.io/en/latest/performance.html#flags).
91+
[Flag](https://docs.python.org/3/library/enum.html#enum.Flag) types are also seamlessly supported! This allows a database column to behave like a bit field and is an alternative to having multiple boolean columns. There are positive performance implications for using a bit field instead of booleans proportional on the size of the bit field and the types of queries you will run against it. For bit fields more than a few bits long the size reduction both speeds up queries and reduces the required storage space. See the documentation for [discussion and benchmarks](https://django-enum.readthedocs.io/en/latest/performance.html#flags).
9292

9393
```python
9494

@@ -112,7 +112,7 @@ Many packages aim to ease usage of Python enumerations as model fields. Most wer
112112

113113
## Complex Enumerations
114114

115-
[django-enum](https://django-enum.readthedocs.io) supports enum types that do not derive from Django's ``IntegerChoices`` and ``TextChoices``. This allows us to use other libs like [enum-properties](https://pypi.org/project/enum-properties) which makes possible very rich enumeration fields:
115+
[django-enum](https://pypi.org/project/django-enum) supports enum types that do not derive from Django's [IntegerChoices](https://docs.djangoproject.com/en/stable/ref/models/fields/#field-choices-enum-types) and [TextChoices](https://docs.djangoproject.com/en/stable/ref/models/fields/#field-choices-enum-types). This allows us to use other libs like [enum-properties](https://pypi.org/project/enum-properties) which makes possible very rich enumeration fields:
116116

117117
``?> pip install enum-properties``
118118

@@ -176,7 +176,7 @@ Many packages aim to ease usage of Python enumerations as model fields. Most wer
176176
assert TextChoicesExample.objects.filter(color='FF0000').first() == instance
177177
```
178178

179-
While they should be unnecessary if you need to integrate with code that expects an interface fully compatible with Django's ``TextChoices`` and ``IntegerChoices`` django-enum provides ``TextChoices``, ``IntegerChoices``, ``FlagChoices`` and ``FloatChoices`` types that derive from enum-properties and Django's ``Choices``. So the above enumeration could also be written:
179+
While they should be unnecessary if you need to integrate with code that expects an interface fully compatible with Django's [TextChoices](https://docs.djangoproject.com/en/stable/ref/models/fields/#field-choices-enum-types) and [IntegerChoices](https://docs.djangoproject.com/en/stable/ref/models/fields/#field-choices-enum-types) [django-enum](https://pypi.org/project/django-enum) provides [TextChoices](https://django-enum.rtfd.io/en/stable/reference/choices.html#django_enum.choices.TextChoices), [IntegerChoices](https://django-enum.rtfd.io/en/stable/reference/choices.html#django_enum.choices.IntegerChoices), [FlagChoices](https://django-enum.rtfd.io/en/stable/reference/choices.html#django_enum.choices.FlagChoices) and [FloatChoices](https://django-enum.rtfd.io/en/stable/reference/choices.html#django_enum.choices.FloatChoices) types that derive from enum-properties and Django's ``Choices``. So the above enumeration could also be written:
180180

181181
```python
182182

@@ -204,23 +204,30 @@ While they should be unnecessary if you need to integrate with code that expects
204204
pip install django-enum
205205
```
206206

207-
``django-enum`` has several optional dependencies that are not pulled in by default. ``EnumFields`` work seamlessly with all Django apps that work with model fields with choices without any additional work. Optional integrations are provided with several popular libraries to extend this basic functionality.
207+
[django-enum](https://pypi.org/project/django-enum) has several optional dependencies that are not installed by default. [EnumField](https://django-enum.rtfd.io/en/stable/reference/fields.html#django_enum.fields.EnumField) works seamlessly with all Django apps that work with model fields with choices without any additional work. Optional integrations are provided with several popular libraries to extend this basic functionality, these include:
208208

209-
Integrations are provided that leverage [enum-properties](https://pypi.org/project/enum-properties) to make enumerations do more work and to provide extended functionality for [django-filter](https://pypi.org/project/django-filter) and [djangorestframework](https://www.django-rest-framework.org).
210209

211-
```bash
212-
pip install enum-properties
213-
pip install django-filter
214-
pip install djangorestframework
215-
```
210+
* [enum-properties](https://pypi.org/project/enum-properties)
211+
```bash
212+
> pip install "django-enum[properties]"
213+
```
214+
* [django-filter](https://pypi.org/project/django-filter)
215+
* [djangorestframework](https://www.django-rest-framework.org)
216+
216217

217-
## Continuous Integration
218+
## Database Support
219+
220+
[![Postgres](https://img.shields.io/badge/Postgres-9.6%2B-blue)](https://www.postgresql.org/)
221+
[![MySQL](https://img.shields.io/badge/MySQL-5.7%2B-blue)](https://www.mysql.com/)
222+
[![MariaDB](https://img.shields.io/badge/MariaDB-10.2%2B-blue)](https://mariadb.org/)
223+
[![SQLite](https://img.shields.io/badge/SQLite-3.8%2B-blue)](https://www.sqlite.org/)
224+
[![Oracle](https://img.shields.io/badge/Oracle-18%2B-blue)](https://www.oracle.com/database/)
218225

219-
Like with Django, Postgres is the preferred database for support. The full test suite is run against all combinations of currently supported versions of Django, Python, and Postgres as well as psycopg3 and psycopg2. The other RDBMS supported by Django are also tested including SQLite, MySQL, MariaDB and Oracle. For these RDBMS (with the exception of Oracle), tests are run against the minimum and maximum supported version combinations to maximize coverage breadth.
226+
Like with [Django](https://www.djangoproject.com), [PostgreSQL](https://www.postgresql.org) is the preferred database for support. The full test suite is run against all combinations of currently supported versions of [Django](https://www.djangoproject.com), [Python](https://www.python.org), and [PostgreSQL](https://www.postgresql.org) as well as [psycopg3](https://pypi.org/project/psycopg) and [psycopg2](https://pypi.org/project/psycopg2). The other RDBMS supported by [Django](https://www.djangoproject.com) are also tested including [SQLite](https://www.sqlite.org), [MySQL](https://www.mysql.com), [MariaDB](https://mariadb.org) and [Oracle](https://www.oracle.com/database). For these RDBMS (with the exception of [Oracle](https://www.oracle.com/database), tests are run against the minimum and maximum supported version combinations to maximize coverage breadth.
220227

221228
**See the [latest test runs](https://github.com/bckohan/django-enum/actions/workflows/test.yml) for our current test matrix**
222229

223-
*For Oracle, only the latest version of the free database is tested against the minimum and maximum supported versions of Python, Django and the cx-Oracle driver.*
230+
For [Oracle](https://www.oracle.com/database), only the latest version of the free database is tested against the minimum and maximum supported versions of Python, Django and the [cx-Oracle](https://pypi.org/project/cx-Oracle) driver.
224231

225232
## Further Reading
226233

doc/source/changelog.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
Change Log
55
==========
66

7-
v2.2.0 (2025-03-07)
7+
v2.2.0 (2025-03-XX)
88
===================
99

10+
* Implemented `Test all example code in the docs <https://github.com/bckohan/django-enum/issues/99>`_
11+
* Implemented `Use intersphinx for doc references <https://github.com/bckohan/django-enum/issues/98>`_
12+
* Implemented `Support Django 5.2 <https://github.com/bckohan/django-enum/issues/96>`_
13+
* Implemented `Upgrade to enum-properties >=2.2 <https://github.com/bckohan/django-enum/issues/95>`_
1014
* Implemented `Move form imports to locally scoped imports where needed in fields.py <https://github.com/bckohan/django-enum/issues/79>`_
15+
* Implemented `Reorganize documentation using diataxis <https://github.com/bckohan/django-enum/issues/72>`_
1116

1217
v2.1.0 (2025-02-24)
1318
===================
@@ -54,7 +59,8 @@ v2.0.0 (2024-09-09)
5459
Migration from 1.x -> 2.x
5560
-------------------------
5661

57-
* Imports of enum-properties_ extended ``TextChoices`` and ``IntegerChoices`` have been changed:
62+
* Imports of :doc:`enum-properties:index` extended ``TextChoices`` and ``IntegerChoices`` have been
63+
changed:
5864

5965
.. code-block:: python
6066

doc/source/conf.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from datetime import datetime
2+
import os
23
import sys
34
from pathlib import Path
45
from sphinx.ext.autodoc import between
56

67
sys.path.append(str(Path(__file__).parent.parent.parent))
78
import django_enum
89

10+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')
11+
912
# Configuration file for the Sphinx documentation builder.
1013
#
1114
# This file only contains a selection of the most common options. For a full
@@ -25,11 +28,9 @@
2528

2629
# -- Project information -----------------------------------------------------
2730

28-
project = 'django_enum'
29-
copyright = f'2022-{datetime.now().year}, Brian Kohan'
30-
author = 'Brian Kohan'
31-
32-
# The full version, including alpha/beta/rc tags
31+
project = django_enum.__title__
32+
copyright = django_enum.__copyright__
33+
author = django_enum.__author__
3334
release = django_enum.__version__
3435

3536

@@ -39,6 +40,8 @@
3940
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4041
# ones.
4142
extensions = [
43+
'sphinxcontrib_django',
44+
'sphinx.ext.intersphinx',
4245
'sphinx.ext.autodoc',
4346
'sphinx.ext.todo'
4447
]
@@ -71,6 +74,17 @@
7174

7275
todo_include_todos = True
7376

77+
intersphinx_mapping = {
78+
"django": (
79+
"https://docs.djangoproject.com/en/stable",
80+
"https://docs.djangoproject.com/en/stable/_objects/",
81+
),
82+
"enum-properties": ("https://enum-properties.readthedocs.io/en/stable", None),
83+
"django-render-static": ("https://django-render-static.readthedocs.io/en/stable", None),
84+
"django-filter": ("https://django-filter.readthedocs.io/en/stable", None),
85+
"python": ('https://docs.python.org/3', None)
86+
}
87+
7488

7589
def setup(app):
7690
# Register a sphinx.ext.autodoc.between listener to ignore everything

0 commit comments

Comments
 (0)