[Django]-Django admin custom list_display

5πŸ‘

βœ…

In first, all methods of class takes first argument self, so you need define you method like:

def display_resort(self, request):
     if request.user.is_super:
         resort_list = ["name", "author", "price"]
     else:
         resort_list = ["name", "author"]
     return resort_list

But isnt a django-way.
You need define get_list_display method in your bookAdmin class:

class bookAdmin(admin.ModelAdmin):

    def get_list_display(self, request):
        default_list_display = super(bookAdmin, self).get_list_display(request)
        if request.user.is_superuser:
            # return any list
        return default_list_display
πŸ‘€freylis

Leave a comment