#22282: models.BooleanField.blank should be 'False' if BooleanField has choices -------------------------------------+------------------------------------- Reporter: django@… | Owner: nobody Type: Uncategorized | Status: closed Component: Database layer | Version: 1.6 (models, ORM) | Resolution: needsinfo Severity: Normal | Triage Stage: Keywords: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 1 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by aaugustin):
* status: new => closed * needs_better_patch: => 0 * resolution: => needsinfo * needs_tests: => 0 * needs_docs: => 0 Comment: Let's start with form fields. A `BooleanField` is rendered by default as a checkbox. If it's mandatory (e.g. accept terms & conditions), you set `blank = False`. If it's optional, you set `blank = True`. Let's now look at model fields. Only the second case makes sense. That's why Django forces `blank = True`. You're right, Django could warn that `blank = False` is a misconfiguration that probably doesn't do what you expect. If I understand correctly, you'd like to use a different widget, maybe a radio list with two choices. If a value that doesn't match either of your choices is returned, as far as I can tell, `BooleanField.to_python` is going to raise a `ValidationError`. I don't understand why you're saying that "There's no way to make sure the value is not blank." On the contrary, Django enforces that you always get `True`, `False` or an exception at the model layer. As explained above, always getting `True` or an execption isn't interesting at the model layer. I'm not sure where "`BooleanField` assumes a `None` value to be `False`" comes from either. Could you show why your example doesn't work? Either an exception traceback or a failing test case will do. Thank you! -- Ticket URL: <https://code.djangoproject.com/ticket/22282#comment:1> 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/078.d95cfa6cfa77cd4678ef0dba19411389%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.