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 stuff to make the inputs readonly
    return MyForm

Then in your view function where you create your inline formset, do
something like: -

def your_main_view_function(request):
    #
    #
    #
    passing_readonly = True
    yourdynamicform = make_my_form(passing_readonly)
    YourFormSet = inlineformset_factory(ModelA, ModelB ,
form=yourdynamicform)
    #
    #
    #

On Oct 23, 4:30 am, Andew Gee <gee.webm...@gmail.com> wrote:
> 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)
>
> but when I try to use it in the inlineformset_factory I get the error
>
> NoneType object is not callable.
>
> I know the problem id the way I am using the MyForm in the inline call
> because I get the same error if I do either of the following
>
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm
> (readOnly=True))
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm())
>
> but it works if I do
>
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm)
>
> obviously the readOnly param defaults to False and my inputs are not
> changed.
>
> Does anyone know how I can pass the readOnly param to MyForm using the
> inlineformset_factory or how else I can achieve what I want?
>
> Thanks
> Andrew
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to