title: How to validate array of choices in Django ModelForm against preset list of choices
body: <p>I have the following model form in my application which features a multiple choice field (think lots of checkboxes) populated from a static array of choices. I want users to be able to select multiple items and the result will be stored in the database as a string separated by commas but the Django validation keeps showing (for example):</p>
  
  <pre><code>&gt;&gt;&gt; bsf = BiomSearchForm({"otu_text": ["Test"], "criteria":"soil"})
  &gt;&gt;&gt; bsf.errors
  {'otu_file': ['This field is required.']}
  &gt;&gt;&gt; bsf = BiomSearchForm({"otu_text": ["Test"], "criteria":["soil", "geothermal"]})
  &gt;&gt;&gt; bsf.errors
  {'otu_file': ['This field is required.'], 'criteria': ["Select a valid choice. ['soil', 'geothermal'] is not one of the available choices."]}
  </code></pre>
  
  <p>These choices are stored in the database for record purposes, they are not tied to any other tables. Is there a way to iterate through the submitted multiple choice array and check if the constituent strings are of the available choices? I found out that if we pass a single string instead of an array, it will validate correctly.</p>
  
  <p>Here are my model and its form:</p>
  
  <pre><code>class BiomSearchJob(models.Model):
      ECOSYSTEM_CHOICES = (
          ("all", "All Ecosystem"),
          ("animal", "Animal/Human"),
          ("anthropogenic", "Anthropogenic"),
          ("freshwater", "Freshwater"),
          ("marine", "Marine"),
          ("soil", "Soil"),
          ("plant", "Plant"),
          ("geothermal", "Geothermal"),
          ("biofilm", "Biofilm"),
      )
  
      user = models.ForeignKey(User, on_delete=models.CASCADE)
      completed = models.BooleanField(default=False)
      criteria = models.CharField(
          default="all", choices=ECOSYSTEM_CHOICES, max_length=200,
      )
      otu_text = models.TextField(default=None)
      created_at = models.DateTimeField(auto_now_add=True)
      updated_at = models.DateTimeField(auto_now=True)
  
      def set_completed(self, completed):
          self.completed = completed
  
  class BiomSearchForm(forms.ModelForm):
      class Meta:
          model = BiomSearchJob
          fields = {
              "otu_text": forms.CharField,
              "otu_file": forms.FileField,
              "criteria": forms.MultipleChoiceField(
                  required=True,
              ),
          }
          labels = {
              "otu_text": "Paste your BIOM table",
              "criteria": "Select the ecosystem",
          }
          widgets = {
              "otu_text": forms.Textarea(attrs={'cols': 30, 'rows': 12}),
              "criteria": forms.CheckboxSelectMultiple,
          }
  
      otu_file = forms.FileField(
          label="or upload your BIOM file",
      )
  </code></pre>