'How to Configure a column not to visible by default in django admin
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
Solution 1:[1]
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)
class FlatPageAdmin(admin.ModelAdmin):
fieldsets = (
(None, {
'fields': ('url', 'title', 'content', 'sites')
}),
('Advanced options', {
'classes': ('collapse',),
'fields': ('registration_required', 'template_name'),
}),
)
The code in your case would be -:
class ProductAdmin(TimestampedModelAdminMixin:
fieldsets = (
(None, {
'fields': ('id', 'active')
})
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
