Thursday, April 28, 2011

Re: form CharField null vs blank

On Thu, 28 Apr 2011 06:18:08 -0700, Brian Craft <bcboy@thecraftstudio.com> wrote:
> A form with a CharField seems to end up with a zero-length string in
> the cleaned_data if the field is not in the form data. Is there any
> good way to avoid this?

Django docs say:

"Note that empty string values will always get stored as empty strings,
not as NULL. Only use null=True for non-string fields such as integers,
booleans and dates. For both types of fields, you will also need to set
blank=True if you wish to permit empty values in forms, as the null
parameter only affects database storage (see blank).

Avoid using null on string-based fields such as CharField and TextField
unless you have an excellent reason. If a string-based field has
null=True, that means it has two possible values for "no data": NULL,
and the empty string. In most cases, it's redundant to have two possible
values for "no data;" Django convention is to use the empty string, not
NULL."


If you really need to get NULL, you've got to do this with your own
validators.

Kind regards

Michael

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

No comments:

Post a Comment