ModelChoiceField and dynamic Querysets

218 views
Skip to first unread message

mwebs

unread,
Sep 5, 2008, 5:11:31 AM9/5/08
to Django users
With the ModelChoiceFiled you can represent relationships between
models.

So my form looks something like this:

class MyForm(forms.Form):
name = forms.CharField()
trials = forms.ModelChoiceField(...)

According to the documentation I have to pass the queryset to the
modelchoicefield.
But how can I do this:

e.g. I want to pass somethiung like this:

queryset = MyModel.objects.filter(a_fk = .., b_fk = null).exclude(...)

How do I pass this to the trials formField? The filter lookup also
takes some variables into account and in my forms.py I dont see a way
to realize this, as I can not pass any arguments.

How can I pass a dynamic generated queryset?
Thanks

mwebs

unread,
Sep 5, 2008, 5:34:21 AM9/5/08
to Django users
Reply all
Reply to author
Forward
0 new messages