-
Notifications
You must be signed in to change notification settings - Fork 68
Allow CharField to define a generic enum type #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Interesting, playing around with it a bit, and it seems like the Django API makes it a little tricky to do this, ideally we'd pass in Something like class FooModel(models.Model):
class BarEnum(models.TextChoices):
FOO = "foo"
BAR = "bar"
some_enum_field = models.CharField(
# something like this would allow for an @overload
enum=BarEnum,
default=BarEnum.FOO,
) |
Also by
Do you mean the set and get would be |
Hey @sbdchd , I always defined enums the old way without the Having said that, allowing to declare the |
This was built on top of #63, so merging it should only keep this PR's change Note that even though the change looks big, it actually is pretty small, it is just that all fields need to define their own `__new__` (or `__init__` if their signature is different from the base field), and it is all the same, the difference is the classname and the generic field. I also added some documentation [here](https://github.com/sbdchd/django-types/pull/65/files#diff-876a5d116ef70c86039fbb8498623871324fa93fc1ae51c7c09ba2a0f7612e99R47) explaining the usage. Fix #34
It would be nice to have support for this: https://docs.djangoproject.com/en/3.2/ref/models/fields/#enumeration-types
Maybe something like this:
This way the typing would know that the field reads and writes that exact enum type and not a str.
The text was updated successfully, but these errors were encountered: