If I understand you correctly, this is what you can do... You can override BaseInlineFormSet
, then manually set the query set for that field on every form in the formset.
So in your forms.py, you would do this:
class BaseBarFormSet(BaseInlineFormSet):
def __init__(self, other_model_queryset, *args, **kwargs):
super(BaseInlineFormSet, self).__init__(*args, **kwargs)
for form in self.forms:
form.fields['other_field'].queryset = other_model_queryset
Note how the first argument to __init__ is the queryset you want to set.
Then in you view, you would just modify your current code accordingly. Pass in that new BaseBarFormSet in the factory function:
FormSet = inlineformset_factory(Foo, Bar, form=BarForm, formset=forms.BaseBarFormSet) # notice formset=forms.BaseBarFormSet
Then pass the queryset you want for the other field to the actual FormSet
class created by the factory function:
formset = FormSet(OtherModel.objects.filter(…), instance=foo) #notice the first parameter
Formsets are very complicated sometimes, so hopefully that made sense… let me know if you have problems.