Huuuze wrote:
> I have defined a zip code field as follows in my Address model:
> 
> zip = models.IntegerField(blank=True, null=True)
> 
> Being a good Djangonaut, I'm using a ModelForm to convert my address
> model into HTML.  Now this where things get dicey.  As you can see in
> the model, zip code can except empty values.  Unfortunately, when I
> attempt to save data entered by a user who has left the zip code field
> blank, I receive a database exception.  Apparently, Django is
> attempting to insert an empty string into my integer-only field.
> 
> From what I can tell, this particular topic has been discussed
> previously:
> 
> http://www.hoboes.com/Mimsy/?ART=595
> 
> Is the solution outlined in the blog post above the long-term solution
> for Django developers or are there plans to have a ModelForm
> understand that I would not want to insert an empty string into an
> integer field?

Are you sure it happens in IntegerFields, that's surprising.  That blog 
is talking about CharFields for which saving "" for None is less surprising.

Instead of mucking with model's save method I'd create my own field, 
NullCharField or NullIntegerField that replaces "" or None with NULL 
according to the null=true parameter.



-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___________________________________________________________________________
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to