It's probably a little more complex than that. When you want to display the current DB value in a form for editing, you're going to have to turn it back into a list.
If I recall correctly, there is a field on djangosnippets that implements storing a multi-select as comma separated values. I don't remember the name, however, so you'll have to search for it. On Thu, Feb 11, 2010 at 10:40 AM, Kevin Audleman <kevin.audle...@gmail.com> wrote: > This must be a fairly common need so I'd love some help figuring out > why I've made it so complicated. > > I've got a CharField "days_available" with choices set to a tuple of > weekdays (e.g. Monday, Tuesday, etc.). > > In my form I am representing this field as a forms.MultipleChoiceField > so that multiple days can be selected. > > When it comes time to save, if I don't do anything then an exception > gets thrown because the form field returns a list [u'Monday', > u'Tuesday']. I found a way to get around this, namely write a clean > function for that field that joins the values with a comma into a > string: > > def clean_days_available(self): > return ",".join(self.cleaned_data['days_available']) > > However this also means that when I load the form I have to convert > that string back into a list. I haven't found a good place to do that > yet so I'm doing it in my view. > > First question: is there a convenient Django function I'm missing that > would be the preferred place to do this? > > Second question: Am I overcomplicating this? > > Thanks, > Kevin > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.