Possible Duplicate:
Django “Enter a list of values” form error when rendering a ManyToManyField as a Textarea
I have python,django,ajax these data in artist input field. I am getting Enter a list of values.error. Will you please help me to save these data? thanks
Model
artist = models.ManyToManyField(ApiArtist, blank=True)
Form and Validation
class ApiSongForm(ModelForm):
class Meta:
model = ApiSong
widgets = {
'artist': forms.TextInput(),
}
def clean_artist(self):
data = self.cleaned_data
artist_list = data.get('artist', None)
if artist_list is not None:
for artist_name in artist_list.split(','):
artist = ApiArtist(name=artist_name).save()
return artist_list
EDIT
Now I’ve changed the code copy/paste from provided link. But and I am getting Cannot resolve keyword 'artist' into field. Choices are: apisong, id, name. error message.
Here is my ApiArtist and SongModel. thanks
class ModelCommaSeparatedChoiceField(ModelMultipleChoiceField):
widget = forms.TextInput
def clean(self, value):
if value is not None:
print value
value = [item.strip() for item in value.split(",")] # remove padding
return super(ModelCommaSeparatedChoiceField, self).clean(value)
class ApiSongForm(ModelForm):
artist = ModelCommaSeparatedChoiceField(
required=False, queryset=ApiArtist.objects.filter(), to_field_name='artist')
class Meta:
model = ApiSong
Now my following code is working. Thanks anyways