On Mon, Nov 16, 2009 at 4:29 AM, Djoume <[email protected]> wrote:
> Dear Djangonauts,
>
> I have read the documentation and I think I understand why we don't
> want to store empty strings as NULL in the database.
>
> I also understand that model validation is being worked on and it's
> not what I'm trying to achieve here.
>
> The question of why CharField default to empty strings has already
> been discussed a couple of years ago on this mailing list, without any
> conclusive answer:
>
> http://groups.google.com/group/django-developers/browse_thread/thread/681a64eeb905da05/1ccd44ea84df1258?lnk=gst&q=empty+string#1ccd44ea84df1258

To my reading, that thread gives a conclusive answer.

> Since CharField (and childs) default to blank=False, why don't they
> have default=None as well?
>
> I believe this would be more consistent with FloatField and
> IntegerField for instance, what am I missing?

Malcolm explains the difference in one of his responses. It all comes
down to form processing.

When you're processing an IntegerField or FloatField on a form, you
can look at the field contents, and if the contents is an empty
string, you can interpret it as a None/NULL. If there is a value, it
needs to be cast to an integer/float.

CharFields don't have this luxury. There's no way to differentiate on
form input between "the user left this field empty and wants to store
a NULL" and "the user left this field empty and wants to store an
empty string".

Django has made a value judgement that an empty field in a form will
be interpreted as an empty string. If you don't like this default
behaviour, you can override it at the form level.

Yours
Russ Magee %-)

--

You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=.


Reply via email to