Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to sort the columns of in admin models? django

Tags:

Sometimes we are able to click on the column then the table will be sorted by what's clicked BUT some are not clickable and I do believe those none clickable are because it's not the fields in the model that it's either a foreign key or M2M

I am wondering if there's a way to make them clickable to sort too?

for example of the following,

title and created_at are clickable but not SET

enter image description here

Thanks in advance for any suggestions and help.

like image 441
Dora Avatar asked Mar 07 '17 01:03

Dora


1 Answers

I'm just guessing your models, but you get the idea.

def ModelAdmin(admin.ModelAdmin):
    list_display = ('title', 'set', 'created_at')

     def set(self, obj):
        return obj.set

    set.admin_order_field = 'set__name'
like image 86
Andrey Shipilov Avatar answered Sep 23 '22 09:09

Andrey Shipilov