如何在Django Admin中默认配置列不可见
我想隐藏一列并使该列可见,但是如果用户想要用户查看列,我尝试过这种方式,但没有用我使用。
Admin.py
class ProductAdmin(TimestampedModelAdminMixin, ConfigurableColumnsMixin, admin.ModelAdmin):
list_display = [
"id",
"comment",
"active",
]
我以这种方式尝试过,但没有起作用。
def get_form(self, request, obj=None, **kwargs):
form = super(ProductAdmin, self).get_form(request, obj, **kwargs)
del form.base_fields["comment"]
return form
I want to hide one column and make the column visdible but if user want the user view the column, i tried this way but did not worked forr me.
admin.py
class ProductAdmin(TimestampedModelAdminMixin, ConfigurableColumnsMixin, admin.ModelAdmin):
list_display = [
"id",
"comment",
"active",
]
I tried with this way but did not worked.
def get_form(self, request, obj=None, **kwargs):
form = super(ProductAdmin, self).get_form(request, obj, **kwargs)
del form.base_fields["comment"]
return form
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在管理类中指定要在
fieldset
中显示的字段。您可以参考文档
fieldset(来自文档)的通用语法(从文档)
中,您的情况中的代码为 - :
You can specify the fields that you want to show in the
fieldset
in the admin class.You can refer to docs here
Generic syntax for fieldset (from the docs)
The code in your case would be -: