On Thu, Dec 4, 2014 at 6:46 PM, inoyon artlover KLANGRAUSCH <inoyonartlo...@googlemail.com> wrote: > Great, it works with one form but not with an another... > Btw. how is it possible to overwrite the 'this field is required' error > message?
You can provide your custom set of default errors to the form field definition, e.g.: my_default_errors = { 'required': 'You better enter this field!', 'invalid': 'You can do better than that!' } class MyForm(forms.Form): some_field = forms.CharField(error_messages=my_default_errors) > > Many thanks and best regards! :) > > Am Donnerstag, 4. Dezember 2014 23:01:15 UTC+1 schrieb larry....@gmail.com: >> >> On Thu, Dec 4, 2014 at 4:54 PM, inoyon artlover KLANGRAUSCH >> <inoyona...@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 -- 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/CACwCsY7MPWAchM0cFiKncTFxf7UYcb%3DDdck%3DXkKfraJybG5-NA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.