-
Notifications
You must be signed in to change notification settings - Fork 46
-
Notifications
You must be signed in to change notification settings - Fork 46
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
define a required field with no default #25
Comments
I agree this behaviour is unintuitive. Definitely likely to lead to bugs. |
I just ran into this same issue, I solved it for now by setting default=models.NOT_PROVIDED
It's not ideal, but the clearest solution I could come up without modifying the library |
wow this is very misleading and README should clarify. |
Hey guys, I see your concern. We are used to have the first member as |
As of now a note on |
It'd be nice if they both support a default probably, I can see the case where you'd want to override the default on a re-used Enum... if it only had to be one though it'd be cleaner if it was on the Enum I guess. The reason |
The default value isn't automatically set anymore (since #48). |
Got the same issue using version 2. @jturme's solution did not work for me so I had to patch the library to keep things working: from django_enumfield import enum
class PatchedEnum(enum.Enum):
@classmethod
def _missing_(cls, value):
if cls.__default__ is not None:
return cls.default()
if value is None:
return None
return super()._missing_(cls, value)
# Then instead of inheriting from enum.Enum, use PatchedEnum. |
@clovis1122 I'm not sure I follow. What is the issue you want to solve exactly? An example of a model would help me understand. |
The code automatically sets the first choice as the default value: https://github.com/5monkeys/django-enumfield/blob/master/django_enumfield/db/fields.py#L16-L17
I think this behavior is misleading because if someone defines a field with no default, he expects the field to have no default assigned so that an error is raised if the field is also required.
Right now, it's impossible to have a required field (
null=False
) with no default that would work as expected in the admin.Setting
default=None
obviously doesn't work as the whole code assumes there is a value.The text was updated successfully, but these errors were encountered: