On Thu, Dec 4, 2014 at 4:54 PM, inoyon artlover KLANGRAUSCH <inoyonartlo...@googlemail.com> wrote: > Hi there, I got a following Form-Class: > > > class CustomUserprofileInterestsForm(forms.ModelForm): > > interests = forms.ModelMultipleChoiceField( > queryset=Interests.objects.all(), > widget=forms.CheckboxSelectMultiple) > > > I want to limit the choices for example to 6 of all displayed. > Is it possible with some optional arguments I don't know somehow? >
You can write your own clean method on the form, e.g.: def clean_interests(self): value = self.cleaned_data['interests'] if len(value) > 6: raise forms.ValidationError("You can't select more than 6 items.") return value See: https://docs.djangoproject.com/en/1.7/ref/forms/validation/#form-and-field-validation -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACwCsY6RAVqscaQf7XwGfQFoz3b1g98RH_DR3hrmhc0nYDNh%3DA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.