I\'m trying to sort a Django Admin list page by a specific value in the objects\' related foreign key set.
Specifically, in the below code, I want the ContentAdmin v
I solved this by extending the get_queryset
method of the ContentAdmin
class. After that, it was just a matter of getting the right ORM query
def get_queryset(self, request):
qs = super(ContentAdmin, self).get_queryset(request)
return qs.filter(score__name='Twitter').order_by('-score__score')
For Django 1.5 and earlier, the method was queryset
.
def queryset(self, request):
qs = super(ContentAdmin, self).queryset(request)
return qs.filter(score__name='Twitter').order_by('-score__score')