Home Ask Login Register

Developers Planet

Your answer is one click away!

Juan Carlos Asuncion February 2016

Django: get_readonly_fields does not return correctly

I would like to ask some assistance in this matter, I would like to set the fields in the admin readonly via get_readonly_fields depending on the model's APP_STATUS

my code:

def get_readonly_fields(self, request, obj=None):
    if obj.APP_STATUS != 1 :
    elif obj.APP_STATUS != 4 :
    return self.readonly_fields

the problem is that only the first if is being rendered as read only, what am I doing wrong? Thanks in advance.


doru February 2016

It can't be done the if branching using != because the conditions doesn't exclude each other: let's say obj.APP_STATUS = 2, this validates both conditions if obj.APP_STATUS != 1 and if obj.APP_STATUS != 4 and whichever is first that will be run.

Post Status

Asked in February 2016
Viewed 2,400 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life