I can't figure out how to make admin able to sort records using custom column - hours_to_deadline
(when they clicks on the column header). In my case, it's timedelta.
class JobAdmin(SuperModelAdmin):
...
list_display = ['id', 'identificator', 'created', 'invoice__estimated_delivery','hours_to_deadline','customer__username', 'language_from__name', 'language_to__name',
'delivery__status', 'confirmed', 'approved', 'invoice__final_price']
...
def hours_to_deadline(self,obj):
try:
return (obj.invoice.estimated_delivery - now())
except:
return None
I found this solution: https://stackoverflow.com/a/15935591/3371056
But in my case, I can't just do sum
or something similar.
Do you know what to do?