danirus / django-comments-xtd

A pluggable Django comments application with thread support, follow-up notifications, mail confirmation, like/dislike flags, moderation, a ReactJS plugin and Bootstrap 5.3.
https://django-comments-xtd.readthedocs.io
BSD 2-Clause "Simplified" License
595 stars 158 forks source link

How to order comment list by num of `likedit` #349

Open tian-yan opened 2 years ago

tian-yan commented 2 years ago

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 commented 2 years ago

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.

tian-yan commented 2 years ago

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 commented 2 years ago

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.