You already have a parameter named year so you should use self.year =
year instead of self.year = kwargs.pop('year'). Same for month and
day.2016-11-12 22:39 GMT+01:00 احسان خراسانی <[email protected]>: > HI > i want to add additional parameters to the queryset in forms > > class Reserve(forms.ModelForm): > > food_name = forms.ModelChoiceField(queryset=Food.objects.all()) > > def __init__(self, year=None, month=None, day=None, *args, **kwargs): > super(Reserve, self).__init__(*args, **kwargs) > > self.year = kwargs.pop('year') > self.month = kwargs.pop('month') > self.day = kwargs.pop('day') > self.fields['food_name'].queryset = Food.objects.filter( > serve_date__year = year, serve_date__month = month, > serve_date__day = day) > > > class Meta: > model = Reservation > fields = ('food_count', 'food_name') > > but its return KeyError: > 'year' > > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/faf6ce5c-ec82-4451-90cd-413864167d1d%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- Cordialement, Coues Ludovic +336 148 743 42 -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTY4iUSPVhj7ZSKJks97RU_XLVR1uyZEidVCyHN87UFXbw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

