Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order a recipe queryset by replies number using django-disqus #80

Open
SalahAdDin opened this issue Mar 8, 2018 · 0 comments
Open

Order a recipe queryset by replies number using django-disqus #80

SalahAdDin opened this issue Mar 8, 2018 · 0 comments

Comments

@SalahAdDin
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant