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 = forms.form_for_model(model_type) for y in f.base_fields.iteritems(): if isinstance(y[1], forms.models.ModelChoiceField): y[1].queryset = (y[1].queryset.model.permissible.all(role=r)) return f 'permissible' is a custom manager hth -richard On 4/14/08, Bram <[EMAIL PROTECTED]> wrote: > > > 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 > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---