Thanks, it works. I'm using this in the __init__ of my form, because I'm
subclassing ModelForm.
Bram
Richard Dahl wrote:
> You could do something like this:
>
> f = forms.form_for_model(modelname)
> f.base_fields['fieldname'].queryset = (query_based_on_variable)
>
> I automatically do this
You could do something like this:
f = forms.form_for_model(modelname)
f.base_fields['fieldname'].queryset = (query_based_on_variable)
I automatically do this for a number of forms (to enforce role-based access)
by looping through the base fields:
get_form(model_type, r):
f =
Hi all,
I'm using a ModelForm with a ModelChoiceField. I need to set the
queryset of this field using a variable that's passed to the form
constructor. I couldn't declare the field in the class itself, because
I don't have access to the variable at the class level. How could I
fix this?
Bram
3 matches
Mail list logo