-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
865b7a3
commit 8052f21
Showing
7 changed files
with
242 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from .fields import ChoicesField # noqa | ||
from .fields import IntegerChoicesField, TextChoicesField # noqa | ||
|
||
__all__ = [ | ||
"ChoicesField", | ||
"TextChoicesField", | ||
"IntegerChoicesField", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[tool.poetry] | ||
name = "django-choices-field" | ||
version = "1.0" | ||
description = "Django field that set/get django's new TextChoices enum." | ||
version = "1.1" | ||
description = "Django field that set/get django's new TextChoices/IntegerChoices enum." | ||
authors = ["Thiago Bellini Ribeiro <[email protected]>"] | ||
license = "MIT" | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
from django.db import models | ||
|
||
from django_choices_field import ChoicesField | ||
from django_choices_field import IntegerChoicesField, TextChoicesField | ||
|
||
|
||
class MyModel(models.Model): | ||
class MyEnum(models.TextChoices): | ||
FOO = "foo", "Foo Description" | ||
BAR = "bar", "Bar Description" | ||
class TextEnum(models.TextChoices): | ||
C_FOO = "foo", "T Foo Description" | ||
C_BAR = "bar", "T Bar Description" | ||
|
||
class IntegerEnum(models.IntegerChoices): | ||
I_FOO = 1, "I Foo Description" | ||
I_BAR = 2, "I Bar Description" | ||
|
||
objects = models.Manager["MyModel"]() | ||
|
||
c_field = ChoicesField( | ||
choices_enum=MyEnum, | ||
default=MyEnum.FOO, | ||
c_field = TextChoicesField( | ||
choices_enum=TextEnum, | ||
default=TextEnum.C_FOO, | ||
) | ||
c_field_nullable = TextChoicesField( | ||
choices_enum=TextEnum, | ||
null=True, | ||
) | ||
i_field = IntegerChoicesField( | ||
choices_enum=IntegerEnum, | ||
default=IntegerEnum.I_FOO, | ||
) | ||
c_field_nullable = ChoicesField( | ||
choices_enum=MyEnum, | ||
i_field_nullable = IntegerChoicesField( | ||
choices_enum=IntegerEnum, | ||
null=True, | ||
) |
Oops, something went wrong.