Skip to content
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
11 changes: 8 additions & 3 deletions doc/source/templatetags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,18 @@ we might define a simple color enumeration like so:

.. code:: python

import typing as t
from django.db import models
from django_enum import EnumField, TextChoices
from enum_properties import p, s
from django_enum import EnumField
from django_enum.choices import TextChoices
from enum_properties import Symmetric, s

class ExampleModel(models.Model):

class Color(TextChoices, s('rgb'), s('hex', case_fold=True)):
class Color(TextChoices):

rgb: t.Annotated[t.Tuple[int, int, int], Symmetric()]
hex: t.Annotated[str, Symmetric(case_fold=True)]

# name value label rgb hex
RED = 'R', 'Red', (1, 0, 0), 'ff0000'
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ PyYAML = { version = ">=5.1,<7.0", optional = true }
django-typer = "^2.1.1"

[tool.poetry.group.dev.dependencies]
django-enum = ">=1.1.0"
django-enum = ">=2.0.0"
enum-properties = ">=1.1.1"
pytest = "^8.0"
pytest-django = ">=4.8.0"
Expand Down
8 changes: 5 additions & 3 deletions tests/enum_app/enums.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum

from enum_properties import EnumProperties, s
from typing_extensions import Annotated
from enum_properties import EnumProperties, Symmetric


class IndependentEnum(Enum):
Expand All @@ -9,7 +9,9 @@ class IndependentEnum(Enum):
VALUE2 = 22


class DependentEnum(EnumProperties, s("indep")):
class DependentEnum(EnumProperties):
indep: Annotated[IndependentEnum, Symmetric()]

VALUE0 = 0, IndependentEnum.VALUE2
VALUE1 = 1, IndependentEnum.VALUE1
VALUE2 = 2, IndependentEnum.VALUE0
22 changes: 17 additions & 5 deletions tests/enum_app/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import typing as t
from typing_extensions import Annotated
from django.db import models
from django_enum import EnumField, IntegerChoices, TextChoices
from enum_properties import p, s
from django_enum import EnumField
from django_enum.choices import IntegerChoices, TextChoices
from enum_properties import Symmetric, s

try:
from django.utils.decorators import classproperty
Expand All @@ -12,7 +15,10 @@ class EnumTester(models.Model):
class NotAnEnum:
pass

class Color(TextChoices, s("rgb"), s("hex", case_fold=True)):
class Color(TextChoices):
rgb: Annotated[t.Tuple[int, int, int], Symmetric()]
hex: Annotated[str, Symmetric(case_fold=True)]

# name value label rgb hex
RED = "R", "Red", (1, 0, 0), "ff0000"
GREEN = "G", "Green", (0, 1, 0), "00ff00"
Expand All @@ -22,13 +28,16 @@ class Color(TextChoices, s("rgb"), s("hex", case_fold=True)):
def class_name(cls):
return cls.__name__

class MapBoxStyle(IntegerChoices, s("slug", case_fold=True), p("version")):
class MapBoxStyle(IntegerChoices):
"""
https://docs.mapbox.com/api/maps/styles/
"""

_symmetric_builtins_ = ["name", "uri", "label"]

slug: Annotated[str, Symmetric(case_fold=True)]
version: int

# name value label slug version
STREETS = 1, "Streets", "streets", 11
OUTDOORS = 2, "Outdoors", "outdoors", 11
Expand All @@ -54,9 +63,12 @@ def docs(cls):
# def __str__(self):
# return self.uri

class AddressRoute(TextChoices, s("alt", case_fold=True), p("str")):
class AddressRoute(TextChoices):
_symmetric_builtins_ = [s("name", case_fold=True)]

alt: Annotated[t.List[str], Symmetric(case_fold=True)]
str: str

# name value alt
ALLEY = (
"ALY",
Expand Down
18 changes: 14 additions & 4 deletions tests/examples/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import typing as t
from django.db import models
from django_enum import EnumField, IntegerChoices, TextChoices
from enum_properties import p, s
from django_enum import EnumField
from django_enum.choices import IntegerChoices, TextChoices
from enum_properties import Symmetric, s
from typing_extensions import Annotated

try:
from django.utils.decorators import classproperty
Expand All @@ -16,19 +19,26 @@ class ExampleModel(models.Model):

define_field = models.CharField(choices=DEFINES, max_length=2)

class Color(TextChoices, s("rgb"), s("hex", case_fold=True)):
class Color(TextChoices):

rgb: Annotated[t.Tuple[int, int, int], Symmetric()]
hex: Annotated[str, Symmetric(case_fold=True)]

# name value label rgb hex
RED = "R", "Red", (1, 0, 0), "ff0000"
GREEN = "G", "Green", (0, 1, 0), "00ff00"
BLUE = "B", "Blue", (0, 0, 1), "0000ff"

class MapBoxStyle(IntegerChoices, s("slug", case_fold=True), p("version")):
class MapBoxStyle(IntegerChoices):
"""
https://docs.mapbox.com/api/maps/styles/
"""

_symmetric_builtins_ = ["name", "uri", "label"]

slug: Annotated[str, Symmetric(case_fold=True)]
version: int

# name value label slug version
STREETS = 1, "Streets", "streets", 11
OUTDOORS = 2, "Outdoors", "outdoors", 11
Expand Down
2 changes: 1 addition & 1 deletion tests/traverse/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django_enum import IntegerChoices, TextChoices
from django_enum.choices import IntegerChoices, TextChoices
from enum_properties import p, s


Expand Down