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 allow superusers to see/change owner
fields=list(fs[0][1]['fields'])
if not request.user.is_superuser:
fields.remove('owner')
return [(None, {'fields': tuple(fields)})]
def queryset(self, request):
if request.user.is_superuser:
return Who.objects.all()
else:
return Who.objects.filter(owner=request.user)
class Meta:
model = Who
admin.site.register(Who,WhoAdmin)
On Apr 23, 12:06 pm, Zain Memon <
z...@inzain.net> wrote:
> 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 23, 2009 at 3:32 AM, phoebebright <
phoebebri...@spamcop.net>wrote:
>
>
>
>
>
> > 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 <
z...@inzain.net> wrote:
> > > You can override the ModelAdmin.save_model() method to check if the
> > current
> > > user has permission to change the owner.
> > > Take a look athttp://
www.b-list.org/weblog/2008/dec/24/admin/tosee an