[Answered ]-Django 1.8.7 get_readonly_fields seems like have a bug

2👍

The bug is not in Django, but in your code. In your get_readonly_fields method you modify the readonly_fields attribute; those modifications persist, since the admin object lives for the lifetime of the process.

Don’t do that. get_readonly_fields is supposed to return a value, not modify the attribute. Just do:

def get_readonly_fields(self, request, obj=None):
    rfo = super(MyAdmin, self).get_readonly_fields(request, obj)
    if not request.user.is_superuser:
        rfo += ('c')
    return rfo

Leave a comment