Skip to content Skip to sidebar Skip to footer

Django 1.8.7 Get_readonly_fields Seems Like Have A Bug

I try something with readonly field in Django 1.8.7, let say I have some code like the following: class MyAdmin(admin.ModelAdmin): readonly_fields = ('a', 'b') def get_rea

Solution 1:

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

Post a Comment for "Django 1.8.7 Get_readonly_fields Seems Like Have A Bug"