Using django and django-voting app, how can I order a queryset according to the votes of each item? -


(I'm new to Python and Django, please stand with me for each other. I'm sorry if this Answer is answered elsewhere and it was not found.)

Let's say I have a link model and can vote on user examples of the link through the Django-voting app. How can I order examples of those links according to their score, e.g. Display those people with high scores first.

I think I can use the get_top manager of the Django-voting, but it will only give me examples of the top scoring link and I will not keep other parameters in mind (for example, those links Which is related to a specific user or paging or whatever).

My guess is that I have to write a custom manager for my link model, where I can filter according to a search. If I think correctly I think through each item Loop is required, check its score, and then give it a list (or dictionary), which will be sorted according to the score of each item.

Edit:

This is a stripped-down version of Link Model:

  class link (models.Model): user = models.ForeignKey ('Auth.User') category = models.ForeignKey (category) date = models.DateTimeField (auto_now_add = true, null = true, blank = true) is_deleted = models.BooleanField (default = False, blank = True) link = ValidLinkManager () Objects = Model. Manager ()  

And when a user votes I have this in my opinion:

  vote. Objects.record_vote (link, user, vote)  

Where the link link is example, the user is an example of Auth.User and the vote is either 1, 0, or -1 ValidLinkManager Filters the link, which is set to true_ I_deleted.

get_top method is not that complicated in the vote manager View your code (In managers.py:12222) you can easily create a version that accepts one filter as another parameter and applies it after creating "objects" in the query, in line 158 - this Just like you can add other filters like you are missing

Maybe you return Jonathan as a patch , And he will keep it in the Django-Voting :)


Comments