Re: ModelForms: overwriting a field using parameters from the form constructor

2008-04-16 Thread Bram DUvigneau
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

Re: ModelForms: overwriting a field using parameters from the form constructor

2008-04-14 Thread Richard Dahl
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 =

ModelForms: overwriting a field using parameters from the form constructor

2008-04-14 Thread Bram
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