Ma Mars
Ma Mars

Reputation: 43

django admin readonly_fields = 'some_field' but create or add cannot edit the same

In the Django admin, I have

    readonly_fields = 'some_field'

However, creating or adding cannot edit the field. How can I accomplish this?

Upvotes: 1

Views: 298

Answers (1)

Rob Bednark
Rob Bednark

Reputation: 28122

def get_readonly_fields(self, request, obj=None): 
    if obj is None:
        return () 
    return self.readonly_fields 

(the answer, per the original poster @Ma_Mars in the question comment django admin readonly_fields = 'some_field' but create or add cannot edit the same )

Upvotes: 1

Related Questions