#23681: NullBooleanSelect should have choices kwarg -----------------------------+-------------------------------------- Reporter: benjaoming | Owner: benjaoming Type: New feature | Status: assigned Component: Forms | Version: master Severity: Normal | Resolution: Keywords: | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 1 | UI/UX: 0 -----------------------------+--------------------------------------
Comment (by benjaoming): Sry, I had a copy paste typo (see edited comment above). I did test it with None/True/False, and it works seemingly fine. But there has to be a good reason why `NullBooleanSelect` has customized methods. If `Select` works perfectly using the above choices, why is there a `NullBooleanSelect`? :) In case we could just replace it with `choices=...` then the following could get rid of `NullBooleanSelect` alltogether... {{{ #!div style="font-size: 80%" Code highlighting: {{{#!python class NullBooleanField(BooleanField): """ A field whose valid values are None, True and False. Invalid values are cleaned to None. """ # THIS ONE GOES! # widget = NullBooleanSelect def __init__(self, *args, **kwargs): self.widget = Select(choices=[(None, _("Unknown")), (True, _("Yes")), (False, _("No"))]) super(NullBooleanField, self).__init__(*args, **kwargs) def to_python(self, value): """ Explicitly checks for the string 'True' and 'False', which is what a hidden field will submit for True and False, and for '1' and '0', which is what a RadioField will submit. Unlike the Booleanfield we need to explicitly check for True, because we are not using the bool() function """ if value in (True, 'True', '1'): return True elif value in (False, 'False', '0'): return False else: return None def validate(self, value): pass }}} }}} -- Ticket URL: <https://code.djangoproject.com/ticket/23681#comment:5> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.62417725ed1942e272ef4b3350c10538%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.