Huuuze wrote:
> Thanks for getting back to me.  You're correct -- that article is not
> a one-for-one match when compared to my problem, so let me tweak my
> question.
> 
> When I attempt to save (my_form.save()) and I leave the zip code field
> blank, I receive the following exception:
> 
> DataError at /person/new/add/
> invalid input syntax for integer: ""
> 
> When I look at the insert statement, sure enough, an empty string is
> attempting to make its way into my zip code field.
> 
> With that being said, do you expect that behavior?  If not, how can I
> correct the issue?  If you do expect that behavior, how can I go about
> creating a NullIntegerField?  This is new territory for me.

I don't know what ver of Django you're using by my version certainly 
appears that it doesn't perform the way you say it does.  i.e. it looks 
like it does not allow "" for Integer fields.

from '/django/db/models/fields/__init__.py'

class IntegerField(Field):
     empty_strings_allowed = False

Although, It's possible my 3min analysis of what empty_strings_allowed 
does is wrong.  You'd have to look closer at the above file but it looks 
like overriding this

     def get_db_prep_save(self, value):
         "Returns field's value prepared for saving into a database."
         return value

is what your after.  I've not done this before though so "caveat 
programmer".


btw, I really think IntegerField is the wrong column type for a zip 
code. They can be upto 11 chars long and have hyphens.  I'd make it 
CharField or maybe even a USZipCodeField from 
'contrib/localflavor/us/forms.py' There's many others in localflavor if 
your flavor isn't US.


-- 
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