[Fixed]-How can I dynamically specify the "list_display" attribute of a django ModelAdmin class?


While asking this question, I stumbled across the answer, so I thought I’d share…

Ticket #14206 indicates that this feature was added to django some time ago (version 1.4, I belive). ModelAdmin classes now support a get_list_display() method:

def get_list_display(self, request):
    if request.user.has_perm('my_app.my_permission'):
        list_display = ('field_1', 'field_2', 'dynamic_field',)
        list_display = ('field_1', 'field_2',)
    return list_display

Leave a comment