title: Django forms custom validation on two fields one or the other
body: <p>I'm struggling with the following and need some guidance, below you will see my form.py. I have two fields called <code>group</code> and <code>single</code>. I need to apply the following rules/validation to them...</p>
  
  <ul>
  <li>A user must either enter a single number or select at least one group but never both</li>
  </ul>
  
  <p>So a user can never select both a group and a enter a single number at the same time, but they must have one or the other. Hope that makes sense?</p>
  
  <p>Because of these rules I cannot just add <code>required = true</code> and need some sort of custom validation. It's this custom validation I''m having problems with.</p>
  
  <p>Could anyone give me an example based on my form of the sort of validation I would need?</p>
  
  <p>Thanks. </p>
  
  <p>Forms.py</p>
  
  <pre><code>class myForm(forms.ModelForm):
      def __init__(self, user=None, *args, **kwargs):
          super(BatchForm, self).__init__(*args, **kwargs)
          if user is not None:
              form_choices = Group.objects.for_user(user).annotate(c=Count('contacts')).filter(c__gt=0)
          else:
              form_choices = Group.objects.all()
          self.fields['group'] = forms.ModelMultipleChoiceField(
              queryset=form_choices, required=False
          )
          self.fields['single'] = forms.CharField(required=False)
  </code></pre>