本文介绍了django显示管理字段按需的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想在django管理界面中隐藏需求的字段,这意味着并非所有参数都是必需的。这只是为了我的软件的客户的可用性。 如果有某些条件,例如 条件未作出: 条件(与我目前的代码): 隐藏是可能的,但仍然存在剩菜。是否可以隐藏类型行,没有这样的剩菜?喜欢当 类Meta: exclude = [type] 设置? (这不可能在运行时修改) 到目前为止,我的代码隐藏管理字段的需求: $($) $ b def __init __(self,* args,** kwargs): super(SubItemForm,self) __init __(* args,** kwargs) if self.instance.type ==SOME CONDITION: self.fields [type]。widget = CompleteHidden() self。字段[type]。label = class Meta: model = SubItem 解决方案添加editable = False到要隐藏在模型类中的字段。 eg to_hide = models.TextField(editable = False) 希望它有帮助。 I'd like to hide fields on demand in the django admin interface, this means not all parameters are necessary. This is only for usability for the customers of my software.If some condition is made, e.g. the type field should be completely hidden.Condition not made:Condition made (with my current code):Hiding is possible, but there remain "leftovers". Is it possible to hide the "type line" complete without such leftovers? Like whenclass Meta: exclude = ["type"]is set? (This isn't possible to modify at runtime)So far my code to hide the admin field on demand:class SubItemForm(ModelForm): def __init__(self, *args, **kwargs): super(SubItemForm, self).__init__(*args, **kwargs) if self.instance.type == "SOME CONDITION": self.fields["type"].widget = CompleteHidden() self.fields["type"].label = "" class Meta: model = SubItem 解决方案 add editable=False to the field you want to hide in model class.e.g. to_hide = models.TextField(editable=False)hope it helps. 这篇关于django显示管理字段按需的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-24 05:39