READ ONLY MODE DJANGO ADMIN

756 views Asked by At

Django Version 1.3 + python2.7

I am working with permissions these days and i find it extremely useful. I want to go in more detail so i have two questions :-

1) How can i implement a read only mode for a model in django admin(including inlines , etc) for users inside a group in the best possible way ? So let say i have a group named "Read Only User" and give them permission of adding and changing that model. Now if these user logs in they should see all the fields in read only mode.

2) One step further from question 1 . After having a read only mode i want the above user to see all fields read only except 3 fields. So let say 50 fields are read only i want them to see 45 read only but 5 fields they can change and POST the data.

What i did :-

def get_readonly_fields(self, request, obj=None):
    readonly_fields = super(SupplierAdmin, self).get_readonly_fields(request, obj)
    if request.user.groups.values('name')[0].get('name') == "Read Only Mode":
        readonly_fields = ('','',.......)
0

There are 0 answers