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,
>
>
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
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
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
4 matches
Mail list logo