Hi all, I am using the CheckboxSelectMultiple widget in several of my forms. I've had a little fun trying to figure out how they map to the database. I am using PostgreSQL and have a model field that looks something like this (these values and names I just typed in):
DAYS_CHOICES = ( ('AN', 'Any'), ('MF', 'Monday-Friday'), ('MO', 'Monday'), ('TU', 'Tuesday'), ('WE', 'Wednesday'), ('TH', 'Thursday'), ('FR', 'Friday'), ('SA', 'Saturday'), ('SU', 'Sunday'), ) days_of_week = models.TextField(blank=True, null=True, choices=DAYS_CHOICES) That field is mapped to a newforms field that looks like: days_of_week = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=Roadshare.DAYS_CHOICES) Now, somewhere between Django and PostgreSQL, the values saved from those multiple checkboxes are getting turned into an "array" data type which is signified in postgres by "text []." This is somewhat curious because there's no real way, AFAIK, to tell Django to make a TextField be a postgres array datatype. So, I made that column into an array datatype by hand. Problem is, I want to be able to save blank data in that field. It's not required data. Django will, as it is designed to do, try to save a blank string into the days_of_week field, if no data is provided from the form. This is a problem because a blank string is not an array. This makes postgres complain about data type mismatching. What I ended up doing, as you may have noticed, is the use the much-cautioned "null=True" option on my TextField. The documentation practically begs you not to do this, but in this case, forcing null for a blank value made the database happy. I just wanted to send this to the list for a few reasons: 1) to see if I'm totally off base here 2) to see if there's a better way 3) to document this oddity in case someone else runs across it Thanks for your time, Alex P.S. When the app used MySQL, there were none of these issues. Probably because of the datatypes involved and Django's translation of those types. That's not to say that MySQL is any better or worse than PostgreSQL, I just wanted to clarify. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---