Actually, what he wanted was just to override a field, and not the whole
form, but he can do it with slight modifications of your code. He would
override the form class he wants to modify, instead of creating a generic
one, and instead of iterating all the fields he would just set the relevant
one(s) read only.

- Paulo

On Wed, Aug 4, 2010 at 4:03 AM, shmengie <[email protected]> wrote:

> I cobbled these two classes together which work very nicely for me,
> wish they could make into django.
> Drop these two classes into a util.py and import them instead of Form
> or ModelForm.  When you want your form readonly instantiate it with
> "form=MyForm(record, readonly=True)"
>
> class roForm(forms.Form):
>    def __init__(self, *args, **kwargs):
>        self.readonly = False
>        if kwargs.has_key('readonly'):
>            if kwargs['readonly']:
>                self.readonly = True
>            kwargs.pop('readonly')
>        super(roForm, self).__init__(*args, **kwargs)
>        if self.readonly:
>            for key in self.fields.iterkeys():
>                self.fields[key].widget.attrs['disabled'] = True
>
>
> class roModelForm(forms.ModelForm):
>    def __init__(self, *args, **kwargs):
>        self.readonly = False
>        if kwargs.has_key('readonly'):
>            if kwargs['readonly']:
>                self.readonly = True
>            kwargs.pop('readonly')
>        super(roModelForm, self).__init__(*args, **kwargs)
>        if self.readonly:
>            for key in self.fields.iterkeys():
>                self.fields[key].widget.attrs['disabled'] = True
>
>
> On Aug 3, 2:36 pm, snipinben <[email protected]> wrote:
> > I was wondering how to make a field readonly when you click on it or want
> to
> > change the record. and i have done that with the readonly_feilds method.
> but
> > that makes it to where you cant add information to that feild when you
> add a
> > new record. is there something i can use where you are not able to edit a
> > feild in the change view, but when you add new, you are able to edit the
> > field until you press save? thanks alot
> > --
> > View this message in context:
> http://old.nabble.com/how-to-make-readonly-in-change-but-editable-in-...
> > Sent from the django-users mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<django-users%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to