I posted something related some time ago and now I'm back. Don't hate
me, you are perfectionist and you should like my way :)
Consider the following example that shows the use of 'choices' for some
kind of Fields, plus the effect of blank=True:
-----
class Test(meta.Model):
    c = meta.CharField("Character", maxlength=30, choices=(("","You
can't select this"),("TRUE","It's true"),("FALSE","It's false"),),
blank=False)
    i = meta.IntegerField("Integer", choices=(("","You can't select
this"),(1,"It's true"),(0,"It's false"),), blank=False)
    b = meta.BooleanField("Boolean", choices=(("","You can't select
this"),(True,"It's true"),(False,"It's false"),), blank=False)
    class META:
        admin = meta.Admin()
------

Admin interface represents Char and Interger fields as _mandatory_
(bold) select box; you can't select the first choice ("You can't select
this") because it maps to a blank value and blank=False. If you do
that, admin interface warns you about this constraint. Perfect.

BooleanFields behaves differently in admin interface: the field name
name ("Boolean") is not in bold style (not mandatory?) and if you
select the first choice ("You can't select this", as before) you get an
error because there is no validation that takes into account
"bank=False" and so the INSERT statement is obviously wrong:
---
Request Method:         POST
Request URL:    http://127.0.0.1:8000/admin/boolean/tests/add/
Exception Type:         ProgrammingError
Exception Value:        ERROR: invalid input syntax for type boolean: ""
INSERT INTO "boolean_tests" ("c","i","b") VALUES ('TRUE','0','')
Exception Location:
        /usr/local/lib/python2.4/site-packages/django/core/db/base.py in
execute, line 9
---

In my opinion this is a bug. Are there some reasons to consider this a
feature?

Thanks,

Emanuele

Reply via email to