Django admin - make all fields readonly

后端 未结 9 1208
春和景丽
春和景丽 2020-12-05 17:56

I\'m trying to make all fields readonly without listing them explicitly.

Something like:

class CustomAdmin(admin.ModelAdmin):
    def get_readonly_fi         


        
9条回答
  •  猫巷女王i
    2020-12-05 18:23

    With get_fieldsets you get all fields from the form

    def get_readonly_fields(self, request, obj=None):
        readonly = []
        for fs in self.get_fieldsets(request, obj):
            if len(fs) > 1:
                readonly += fs[1].get('fields', [])
        return readonly
    

提交回复
热议问题