Friday, March 11, 2011

Re: How to limit a ManyToManyField to three choices?

Dnia 11-03-2011 o 21:39:01 bagheera <neostead@go2.pl> napisał(a):

> Dnia 11-03-2011 o 21:29:29 greenie2600 <greenie2600@gmail.com>
> napisał(a):
>
>> bagheera -
>>
>> I had seen the limit_choices_to parameter, but I thought it controlled
>> *which* choices are available to the user - not *how many* they're
>> allowed to choose.
>>
>> I want to show the user a list of 20 or 30 cuisines, but forbid them
>> from checking more than three.
>>
>> Can you show me an example of how I'd use limit_choices_to to limit
>> the *number* of choices the user can select?
>>
>
> Form validation.
>
> this should work
>
> class RestaurantForm(forms.ModelForm):
> cuisines = forms.ModelMultipleChoiceField(Sklep)
>
> class Meta:
> model = Restaurant
> def clean_sklepy(self):
> cuisines_clean = self.cleaned_data[cuisines]
> if len(cuisines_clean) > 3:
> raise forms.ValidationError('You can't choose more than
> three items!')
> return cuisines_clean
>
>
>
>
Sorry, i left some of my code :P But u got the idea.

--
Linux user

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate