[Answered ]-KeyError overriding django ModelAdmin.get_readonly_fields()

2👍

Aha. The issue was my prepopulated_fields value:

prepopulated_fields = {'slug': ('title',)}

Looks like making title readonly made it unavailable to prepopulate the slug field. But that’s OK with me since the user will have to change the slug anyway, so I added this override of get_prepopulated_fields() that makes the same conditional check as I have in get_readonly_fields():

def get_prepopulated_fields(self, request, obj=None):
    if obj and obj.global_status == AVAILABLE_STORY:
        return {}
    return self.prepopulated_fields 
👤tated

Leave a comment