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

How to order comment list by num of likedit #349

Open
tian-yan opened this issue Oct 21, 2021 · 3 comments
Open

How to order comment list by num of likedit #349

tian-yan opened this issue Oct 21, 2021 · 3 comments
Milestone

Comments

@tian-yan
Copy link

I want to order comment list of an article by num of likedit in descending manner.
I tried Query Expression,

in settings.py
COMMENTS_XTD_LIST_ORDER = (Length('likedit_users'), '-submit_date')

but failed with error Exception Value: | Cannot resolve keyword 'likedit_users' into field.
It seems that the only way out is adding an extra field (num_of_likes for example) to the Comment model.

Before I customize the django-comments-xtd package by modifying the source code locally, I want to double confirm if there is any other easy ways to achieve the requirement without source code modifying?

@danirus
Copy link
Owner

danirus commented Oct 21, 2021

With v2.x is not possible because of the relationship between XtdComment and CommentFlag. However in the branch v3.0.0 there is a new CommentReaction model that allows those queries. In this comment I explained how to set up the demo project of v3.0.0.

It loads many comments from the fixtures directory, but I have not created yet a reactions fixture file. There are a number of users loaded in the User model, you can use any of the following. To login use the email address of the user, and the password is the part before the @:

I have not created yet a fixture file with reactions, but you can send some with those users. You will see that the app in v3 doesn't have yet JavaScript, but it's fully functional without it.
Also take a look at the module demo/project/project/enums.py. That module extends the default 2 available reactions (like and dislike), so that the demo project allows users to send Like, Dislike, Smile, Confused, Great, Heart, Rocket, and Eyes reactions (emulating the reactions supported by GitHub comments).

After you have a few reactions you can query comments ordered by '-reactions':

XtdComment.objects.filter(reactions__gt=0).order_by('reactions')

or you can query for specific reactions:

XtdComment.objects.filter(reactions__reaction='+').order_by('reactions')

v3.0.0 is already in a good shape, only that the JavaScript side of app is still under development.

@danirus danirus added this to the 3.0.0 milestone Oct 21, 2021
@tian-yan
Copy link
Author

tian-yan commented Oct 21, 2021

Thank you for your prompt reply and efforts on the project. So far, my website does not use any JavaScript in both front-end and backend, my intention is to build an website with 0 JavaScript, front-end is all Pure CSS.
Do we have an estimated release date for v3.0.0 ?

@danirus
Copy link
Owner

danirus commented Oct 26, 2021

Sounds excellent to me. JavaScript can do a lot but it's not always the answer.

I want to release v3.0.0 before the end of the year.
It sounds indulgent :-) but I can't really put an estimate.

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

2 participants