arthurk / django-disqus

Integrates DISQUS into Django

Home Page:http://django-disqus.readthedocs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Order a recipe queryset by replies number using django-disqus

SalahAdDin opened this issue · comments

I have a recipe model and i need create a view for most commented recipes, i'm using django-disqus for handling recipe's comments, but i don't know how can i order the queryset by the recipe's comment number.

    class PopRecipeListView(GlobalQueryMixin, ListView):
        model = Recipe
        context_object_name = "recipe_list"
        template_name = 'recipe/recipe_top_list.html'
    
        def get_queryset(self):
            qs = super(PopRecipeListView, self).get_queryset()
    
            if qs:
                qs = qs.extra(
                    select={
                        'comments': # get comment numbers
                    }
                ).filter(shared=True).order_by('-rate')[:20]
    
            return qs

Question here.
What's the properly way?