Re: Passing Parameter to form in inlineformset_factory

2009-10-25 Thread Andew Gee
Thanks for the help. I did find this as a solution ad it seems to work Formset = inlineformset_factory(ModelA, ModelB form=MyForm) Formset.form = staticmethod(curry(MyForm, reaOnly=readOnlyvalue)) myFormset = Formset(request.Files, instance=modelAInst) Regards Andrew Andew Gee wrote: > Hi, > >

Re: Passing Parameter to form in inlineformset_factory

2009-10-23 Thread chefsmart
This is coming off untested, but with a couple of tweaks it should work. Try creating a dynamic class. In your views.py, do something like this: - def make_my_form(readonly): class MyForm(forms.ModelForm): def __init__(self, *args, **kwargs): if readOnly: Do stuf

Re: Passing Parameter to form in inlineformset_factory

2009-10-23 Thread pjrhar...@gmail.com
Try using a lambda function. The problem is that the factory wants a callable that creates a form, not a form instance (ie it wants to be able to execute MyForm() for each form in the formset. Formset = inlineformset_factory(ModelA, ModelB form=lambda: MyForm (readOnly=True)) Note I've not tried

Passing Parameter to form in inlineformset_factory

2009-10-22 Thread Andew Gee
Hi, I have the following Form defined class MyForm(ModelForm) def __init__(self, readOnly=False, *args, **kwargs): if readOnly: Do stuff to make the inputs readonly MyForm works perfectly when I instantiate it in the view as a form form = MyForm(readOnly=True, instance=ModelA