django admin how to display widget on readonly field

前端 未结 2 791
野性不改
野性不改 2021-02-08 12:09

I want to display my widget on the field at django admin when the field is readonly.

admin.py

class AudioTrackAdminInline(admin.StackedI         


        
2条回答
  •  旧巷少年郎
    2021-02-08 12:22

    I would say it's a feature.

    When field is set to readonly, Django uses display_for_field function which hardcodes the result, you can't customize it.

    Another approach would be not to set the field as readonly and override formfield_for_dbfield, an undocumented ModelAdmin method and act accordingly to your needs.

提交回复
热议问题