(I am new to python and django, so please bear with me for a second. I apologize if it was answered elsewhere and could not find it)
Say I have a Link model, and through the django voting app, you can vote for link instances. How can I order these link instances according to their invoice, for example. first display those with the highest score.
I suppose I could use the get_top manager for django-voting, but that would give me only the best link instances and not take into account other parameters that I would like to add (for example, those links that belong to a specific user or paging or whatever something else).
My guess would be to write a custom manager for my Link model, where I can filter out a set of queries according to each number of points. If I understand correctly what will require me to scroll through each element, check its rating, and then put a list (or dictionary) in it, which will then be sorted according to the count of each element. This does not return a query, but a dictionary with each element.
Did I miss something?
edit:
Here's a stripped down version of the 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) links = ValidLinkManager() objects = models.Manager()
and when the user votes, I have this in my opinion:
Vote.objects.record_vote(link, user, vote)
where the link is an instance of the link, the user is an instance of auth.User, and the vote is 1, 0, or -1. ValidLinkManager simply filters out links for which is_deleted is set to True.
django sql-order-by
Nicolas r
source share