Create a hidden field in the admin site

前端 未结 5 768
孤街浪徒
孤街浪徒 2021-01-11 18:57

How can I create a fully hidden field (input and label) in the admin site? I know about the exclude property, but it fully excludes the field from the template,

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-11 19:32

    I found it quite handy to use the 'classes' attribute in fieldsets to hide fields but still leave them in a request. In your model admin you can write

    fieldsets = [
            ('Visible Fields', 
             {'fields': [('name', 'comment'),]}),
            ('Collapsable Fields', 
             {'fields': [('rare_property',)],'classes': ['collapse']}),
            ('Hidden Fields', 
             {'fields': [('magic_property',)],'classes': ['hidden']}),
                ]
    

提交回复
热议问题