Changing queryset of a ModelChoiceField

1
2
3
4
5
6
class EventForm(forms.Form):
    events = forms.ModelChoiceField(queryset=Contest.objects.none(), required=True)

    def __init__(self, eventUser, *args, **kwargs):
        super(EventForm, self).__init__(*args, **kwargs)
        self.fields['events'].queryset = Event.objects.filter(user__exact = eventUser.id)

More like this

  1. ModelChoiceField with option groups by anentropic 2 years, 4 months ago
  2. Lazy options on ModelForm fields - like setting a ModelChoiceField queryset from the view by jpic 5 years, 3 months ago
  3. ModelChoiceField with optiongroups by anentropic 4 years, 1 month ago
  4. A Lazy ModelChoiceField implementation by alecdotico 9 months, 1 week ago
  5. ModelChoiceField with choice groups for recursive relationships by estecb 3 months ago

Comments

(Forgotten your password?)