Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4613724
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:35:41+00:00 2026-05-22T01:35:41+00:00

UPDATE : All I am trying to do is get the list of objects

  • 0

UPDATE:

All I am trying to do is get the list of objects based on their voting score and send it to the template. If you have used django-voting before please help me figure this one out. I need a list because I pass that list to the paginator app.

Should I ask a different question (and maybe close this one)?


I am trying to get all the objects in order of the score they have, append them to a list and send it across to the template but I am getting errors. Can you please show me a quick to retrieve my objects in order of their voting score?

get_top() method is from django-voting app managers: link the method on github:

https://github.com/brosner/django-voting/blob/master/voting/managers.py#L122

I am getting all comments in my View as:

comments_all = Vote.objects.get_top(Comment, 100, False) 

"""URL param is latest, then sort by datetime
else sort by vote count, default"""
if sort == 'latest':
    comments_all = Comment.objects.filter(book=book_id, active=True)\
    .order_by('-created_datetime', '-modified_datetime')
else:
    comments_all = Vote.objects.get_top(Comment, 100, False)

"""Pagination: if there is no page, set it to 1"""
comments_paginator = Paginator(comments_all, 20)
try:
    page = int(request.GET.get('page', '1'))
except ValueError:
    page = 1

#pagination: get the pages.
try:
    comments_page = comments_paginator.page(page)
except (EmptyPage, InvalidPage):
    comments_page = comments_paginator.page(comments_paginator.num_pages)

Error Trace:

    Traceback:

    File "/Users/AJ/work/projects/virtual_environments/bottledink/lib/python2.6/site-    packages/django/core/handlers/base.py" in get_response
    111. response = callback(request, *callback_args,   **callback_kwargs)

    File "/Users/AJ/work/projects/bottledink/../bottledink/main/views.py" in show_book
    74.  comments_page = comments_paginator.page(page) 

    File "/Users/AJ/work/projects/virtual_environments/bottledink/lib/python2.6/site-packages/django/core/paginator.py" in page
    37. number = self.validate_number(number)

    File "/Users/AJ/work/projects/virtual_environments/bottledink/lib/python2.6/site-packages/django/core/paginator.py" in validate_number
    28.   if number > self.num_pages:

    File "/Users/AJ/work/projects/virtual_environments/bottledink/lib/python2.6/site-packages/django/core/paginator.py" in _get_num_pages
    60.  if self.count == 0 and not self.allow_empty_first_page:

    File "/Users/AJ/work/projects/virtual_environments/bottledink/lib/python2.6/site-packages/django/core/paginator.py" in _get_count
    53.   self._count = len(self.object_list)

Exception Value: object of type 'generator' has no len()

UPDATE: I tried to do:

comments_all = list(Vote.objects.get_top(Comment, 100, False))

but it gives error:

int() argument must be a string or a number, not 'tuple'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:35:42+00:00Added an answer on May 22, 2026 at 1:35 am

    http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#generic-relations-and-aggregation
    “Django’s database aggregation API doesn’t work with a GenericRelation. For example, you might be tempted to try something like”

    You can use
    https://github.com/coleifer/django-generic-aggregation

    from django.contrib.comments.models import Comment
    from django.db.models import Sum
    from generic_aggregation import generic_annotate
    from voting.models import Vote
    
    #want might to filter on is_public and is_removed
    top = generic_annotate(Comment.objects.all(), Vote.object, Sum('vote')).filter(active=True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I get a list of all the model objects that have a
I'm trying to get a list of all users and all groups on Mac
I am trying to get all users that are updated maximum 90 seconds ago:
I am trying to update all records in a column so that they start
I am trying to block all default methods except create and update in my
I'm trying to do a single row insert/update on a table but all the
i am having a issue with treeview liststore trying to get a real-time update,
I have a DataGridView to which I've set a list of objects to the
I'm trying to get all the children of a category: def list_sub(self, category_name): #
I have ImageMagick installed on my CentOS linux server. I am trying to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.