I have a model include some columns: A,B,C.When the logger is superuser,the list_display will includes all the columns(A,B,C),otherwise,other user can only see part of the columns,for example:B and C.Most of the related answer is user get_form(...),but this is alter the 'exclude','fields' and 'fieldsets',I want alter the list_dispaly.
You would use the changelist_view
method to edit list_display
:
class MyModelAdmin(admin.ModelAdmin):
list_display = ('A', 'B', 'C',)
def changelist_view(self, request, extra_context=None):
if not request.user.is_superuser:
self.list_display = ('B', 'C',)
return super(MyModelAdmin, self).changelist_view(request, extra_context)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With