#10792 closed (fixed)
documentation error on ModelForm ModelChoiceField empty option
Reported by: | Carl Meyer | Owned by: | Carl Meyer |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The ModelForms documentation at the bottom of the "field types" list states:
The blank choice will not be included if the model field has blank=False and an explicit default value (the default value will be initially selected instead).
It is true that the default value is initially selected if given, but it is not true that the "blank choice will not be included". It is included regardless, unless empty_label is explicitly set to None.
I would consider the documented behavior here to be better than the actual behavior, but given backwards-compatibility it's probably the docs that need to change.
Attachments (1)
Change History (7)
comment:1 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Great, I was hoping that would be the answer. Patch attached.
The current patch means that if someone has a ModelChoiceField with required=True and an initial value, they cannot use empty_label to force the creation of an empty option. I can't think of a use case for this, but if we want to preserve that possibility it will mean complicating the empty_label argument a bit: giving it some default sentinel value (normally would be None, but since that has meaning in this case we can't use it) so we know when it's been set explicitly.
comment:3 by , 16 years ago
Has patch: | set |
---|
comment:4 by , 16 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:5 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
The current behaviour sounds like a bug. We fix bugs, rather than documenting around them. There's no real backwards-compat problem here, since there's no good reason to include the blank option in those cases. Would be nice to fix this for 1.1 if you feel like knocking up a patch.