[Django]-Django Order Ascending & Descending

3👍

You can use order_by(‘-thread’), like this :

Comment.objects.filter(thread__in=t).values('thread').annotate(total=Count('thread__id')).order_by('-thread')

And if you want to order records by rating of thread model,You can use double underscore “__” on thread key for foreign key lookup,
like this :

# rating likes

Comment.objects.filter(thread__in=t).values('thread').annotate(total=Count('thread__id')).order_by('thread__rating_likes')

Use this in all your queries as per the requirements.

Leave a comment