django-disqus icon indicating copy to clipboard operation
django-disqus copied to clipboard

Order a recipe queryset by replies number using django-disqus

Open SalahAdDin opened this issue 6 years ago • 0 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?

SalahAdDin avatar Mar 08 '18 18:03 SalahAdDin