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 1 year, 6 months ago
  2. CustomChoiceField, Selectable label field version of ModelChoiceField by mauro 5 years, 3 months ago
  3. filtered ModelChoiceField queries by robharvey 5 years, 3 months ago
  4. ModelChoiceField with optiongroups by anentropic 3 years, 2 months ago
  5. Adding buttons to submit line in a Admin page by marinho 5 years, 1 month ago

Comments

(Forgotten your password?)