Admin site pages + display or hiding instance owner field

2010-01-19 Thread Massimiliano della Rovere
Is there a way to show or hide a model field in a admin site "change" page depending upon the value of request.user.is_superuser ? I was thinking about filling ModelAdmin.field or .fieldset depending on the value of request.user, but how to read the value of request in ? Also .readonly_fields when

Re: Admin site pages + display or hiding instance owner field

2010-01-19 Thread Tim
I think it should be pretty easy to do. The get_form() method on ModelAdmin returns the form, and it knows about the current request. So you could modify that to remove the field after the form is generated. class MyModelAdmin(admin.ModelAdmin): def get_form(self, request, obj=None, **kwarg

Re: Admin site pages + display or hiding instance owner field

2010-01-19 Thread Massimiliano della Rovere
Thanks for your answer Tim. def get_form(self, request, obj=None, **kwargs): form = super(RowModelAdmin, self).get_form(request, obj, **kwargs) if not request.user.is_superuser: * **del form['compilatore']* return form It seems that the object returned by get_form does not behave like a dict().

Re: Admin site pages + display or hiding instance owner field

2010-01-20 Thread Massimiliano della Rovere
Ok I managed to remove the compilatore field from the form (this RowModelAdmin class is used by many Models, all having the compilatore field) def get_form(self, request, obj=None, **kwargs): form = super(RowModelAdmin, self).get_form(request, obj, **kwargs) if not request.user.is_superuser: del

Re: Admin site pages + display or hiding instance owner field

2010-01-20 Thread Massimiliano della Rovere
Solved. It seems this is due to the 1.2 alpha1 bug involving form.is_valid(): http://www.pubbs.net/django/201001/16447/ reverting to django 1.1 solved all my problems On Wed, Jan 20, 2010 at 10:25, Massimiliano della Rovere < massimiliano.dellarov...@gmail.com> wrote: > Ok I managed to remove the