Re: Only show field in admin for superuser

2009-05-09 Thread phoebebright
Just a postscript to this - this will fail if the field being left out is a required field. The admin form will show an error but as the field is missing you will not know what the error is. I think with the new hidden_fields option, this will be a workaround. On Apr 23, 8:20 pm, phoebebright

Re: Only show field in admin for superuser

2009-04-23 Thread phoebebright
That just what I needed! Many thanks. Here is the code that worked for me: class WhoAdmin(admin.ModelAdmin): fields = ('name','owner') def get_fieldsets(self, request, obj=None): fs = super(WhoAdmin, self).get_fieldsets(request, obj) # only allo

Re: Only show field in admin for superuser

2009-04-23 Thread Zain Memon
In that case, try overriding ModelAdmin.get_fieldsets(); add the owner field to self.fieldset if request.user.is_superuser, and then call super.get_fieldsets(). For reference, you can find get_fieldsets() (and other beautiful things you can override) in django/contrib/admin/options.py. On Thu, Apr

Re: Only show field in admin for superuser

2009-04-23 Thread phoebebright
Zain, Thanks for responding. I would really prefer not to show the field at all - I don't want ordinary users being able to see a list of all the users on the system! Phoebe On Apr 23, 9:42 am, Zain Memon wrote: > You can override the ModelAdmin.save_model() method to check if the current > us

Re: Only show field in admin for superuser

2009-04-23 Thread Zain Memon
You can override the ModelAdmin.save_model() method to check if the current user has permission to change the owner. Take a look at http://www.b-list.org/weblog/2008/dec/24/admin/ to see an example. On Thu, Apr 23, 2009 at 1:37 AM, phoebebright wrote: > > I have a model with an owner field that I

Only show field in admin for superuser

2009-04-23 Thread phoebebright
I have a model with an owner field that I only want a superuser to be able to change. I can't change the list of fields in form in admin.py because there is not request.user to test at that time. If I were using custom templates I could put it in the template, but would rather stick to the stand