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? On Mar 11, 2:35 pm, bagheera <[email protected]> wrote: > Dnia 11-03-2011 o 18:06:43 greenie2600 <[email protected]> napisał(a): > > > Hi all - > > > I have two models with a many-to-many relationship: Restaurant and > > Cuisine. The Cuisine table contains, e.g., "Italian", "Mexican", > > "Chinese", etc. Each Restaurant record can be associated with one or > > more Cuisines. > > > Here's the thing: I'd like to limit this to three Cuisines per > > Restaurant. So when editing the record for "Bob's Pan-Asian Buffet", > > the user would be able to check "Japanese", "Chinese", and "Korean", > > but wouldn't be able to check a fourth box. > > > My question: can this be enforced within the model, or is this > > something I'd have to build into my interface layer? > > You can limit choices on model level: > > http://docs.djangoproject.com/en/1.2/ref/models/fields/#django.db.mod... > > If query is too complicated (cuz u want to access object's data, witch > isn't yet available), you still can limit choices on form level, by > overriding __init__ > > class RestaurantForm(forms.ModelForm): > cuisines = forms.ModelMultipleChoiceField(Sklep) > > class Meta: > model = Restaurant > > def __init__(self, *args, **kwargs): > super(RestaurantForm, self).__init__(*args, **kwargs) > self.fields[cuisines].queryset = > Cuisine.objects.filter(pk__in=[fancy query]) > > -- > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

