Readonly for existing items only in Django admin inline

前端 未结 7 1292
长发绾君心
长发绾君心 2020-12-13 14:27

I have a tabular inline model in the Django admin. I need 1 of the fields to not be changeable after it has been created, but setting it as readonly (via readonly_fields) wh

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 15:10

    You can achieve this with only a single inline like so:

    class MyInline(admin.TabularInline):
        fields = [...]
        extra = 0
    
        def has_change_permission(self, request, obj):
            return False
    

提交回复
热议问题