In response to your side question: http://www.djangoproject.com/documentation/model-api/#null
-Brian On Jun 25, 2:12 pm, Huuuze <[EMAIL PROTECTED]> wrote: > Between you and Karen, I've resolved the problem. I had a bug here: > > >> zip = forms.CharField(max_length=5, widget=widgets.TextInput({'size':5}), > >> required=False) > > That code has been changed to: > > >> zip = forms.IntegerField(widget=widgets.TextInput({'size':5, > >> 'maxlength':5}), required=False) > > And good call on the USZipCodeField widget. I'll be certain to make > us of that. > > Side question: I have noticed that empty CharFields (i.e., an empty > middle name value) get empty string values in the database rather than > null values. This seems odd. Is that by design with Django? Here is > the code from my model for that ultimately gets rendered by my > ModelForm: > > >> middle_name = models.CharField(max_length=30, blank=True, null=True) > > On Jun 25, 5:02 pm, "Norman Harman" <[EMAIL PROTECTED]> wrote: > > > 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 -~----------~----~----~----~------~----~------~--~---