Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8686117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:45:27+00:00 2026-06-12T22:45:27+00:00

Possible Duplicate: Django Enter a list of values form error when rendering a ManyToManyField

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:45:29+00:00Added an answer on June 12, 2026 at 10:45 pm

    Now my following code is working. Thanks anyways

    class ApiSongForm(ModelForm):
        artist = forms.CharField()
    
        def save(self, commit=True):
            instance = super(ApiSongForm, self).save(commit=commit)
            artists = self.cleaned_data.get('artist', None)
            if artists is not None:
                for artist_name in artists.split(","):
                    artist = ApiArtist.objects.create(name=artist_name)
                    instance.artist.add(artist)
    
            instance.save()
            return instance
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Override django-admin edit form field values for encrypted data The inline model
Possible Duplicate: Asynchronous HTTP calls in Python I have a Django view which needs
Possible Duplicate: Python : how to append new elements in a list of list?
Possible Duplicate: Can I have a Django model that has a foreign key reference
Possible Duplicate: Unable to get a list of installed Python modules How do I
Possible Duplicate: Django template can’t loop defaultdict I am wondering why my defaultdict(list) will
Possible Duplicate: Django get a model's fields I have next model: class People(models.Model): name
Possible Duplicate: Django models: default value for column I have created a model field
Possible Duplicate: Understanding Python decorators I was reading a django app source code where
Possible Duplicate: How do you select between two dates with Django I have django

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.