Readonly fields in the django admin/inline

后端 未结 3 939
逝去的感伤
逝去的感伤 2021-02-08 09:24

I use this snippet to show several fields in my admin backend as readonly, but as noticed in the comments, it does not work on stackedinline/tabularinline. Is there any other wa

3条回答
  •  日久生厌
    2021-02-08 10:23

    As is the case with JQuery, it seems you can achieve this by changing an attr called "disabled" (works in my Safari, OK we're now in 2013 :-) ). Example below:

    def get_form(self, request, obj=None, **kwargs):
            result = super(, self).get_form(request, obj=obj, **kwargs)
            result.base_fields[].widget.attrs['disabled'] = 'disabled'
            return result
    

提交回复
热议问题