I have a couple models lets call them Model A and Model B. There is a foreign key to A from B.
That is the cardinality between A and B is 1:n.
I have made a corresponding ModelForm for B called MF_B. I have an additional field I define in B. e.g.
class MF_B(forms.ModelForm):
stuff = forms.MultipleChoiceField(queryset=None, required=False)
class Meta:
model=B
as the code above implies, I want to populate the choices here with a queryset. (i've omitted the override code in init() that we would use to set the queryset on the stuff field)
The deal is I want to use inlineformset_factory to create on one page a form with A and several forms with B.
I wanted to just pass a bunch of new kwargs to inlineformset_factory but it kept complaing about unexpected keyword arguments and after looking at the backend code in django, I understand why: inlineformset_factory doesn't take custom kwargs. it only takes kwargs defined in the method sig.
def inlineformset_factory(parent_model, model, form=ModelForm,
formset=BaseInlineFormSet, fk_name=None,
fields=None, exclude=None,
extra=3, can_order=False, can_delete=True, max_num=None,
formfield_callback=None):
I don't think ican use formfield_callback because i need to pass self.request.user to filter objects that come back in the queryset.
any suggestions?