On Apr 29, 3:43 pm, Nick <n...@njday.com> wrote:
> Hi,
>
> I would like to set some fields to be readonly in the Admin app based
> on some logic, and would like to use the new readonly_fields attribute
> of ModelAdmin if possible (rather than some other sort of hack).
>
> I'm trying to access readonly_fields, but get the error "'GalleryForm'
> object has no attribute 'readonly_fields'"
>
> My code is currently as follows:
>
> class GalleryAdminForm(forms.ModelForm):
>         class Meta:
>                 model = Gallery
>         def __init__(self, *args, **kwargs):
>                 super(GalleryAdminForm, self).__init__(*args, **kwargs)
>                 print self.readonly_fields
>
> Any help on how I can access readonly_fields from the ModelForm to
> override it would be really helpful!
>
> Thanks,
> Nick
>

I haven't played with it myself, but surely readonly_fields is an
attribute of the ModelAdmin subclass, not the form?

It looks like there's a get_readonly_fields method on the base
ModelAdmin class, which takes the request as a parameter, so you
should be able to override that and return a customised tuple as
required.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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