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

  • SEARCH
  • Home
  • 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 8069947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:14:01+00:00 2026-06-05T13:14:01+00:00

I have a generic list view in Django which returns around 300 objects (unless

  • 0

I have a generic list view in Django which returns around 300 objects (unless a search is performed).

I have pagination set to only display 10 of the objects.

So I query the database, then iterate through the objects, processing them and adding extra values before the display. I noticed that all 300 objects get the processing done, and the pagination is done after the processing. So I want to only do the processing on the objects that are going to displayed to increase performance.

I calculate the indexes of the objects in the queryset that should be processed 0-10 for page 1, 11-20 for page 2, 21-30 for page 3, etc.

Now I want to process only the objects in the display range but return the full queryset (so the genreic view works as expected).

Initially I tried:

for object in queryset[slice_start:slice_end] :
     # process things here

return queryset

But the slicing seems to return a new queryset, and the original queryset objects do not have any of the calculated values.

Currently my solution is:

index = -1
for object in queryset:
     index += 1   
     if index < slice_start or index > slice_end : continue
     # process things here
return queryset 

Now this works, but it seems rather hacky, and unelegant for Python.
Is there a more pythonic way to do this?

  • 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-06-05T13:14:03+00:00Added an answer on June 5, 2026 at 1:14 pm

    If you’re using Django’s Paginator class (docs), then you can request the current page and iterate over those objects in the view:

    from django.core.paginator import Paginator
    
    # in the view:
    p = Paginator(objects, 2)
    page = p.page(current_page)
    for o in page.object_list:
        # do processing
        pass
    

    You can obtain the value for current_page from the request’s parameters (e.g, a page parameter in request.GET).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have generic list which must be a preserved order so I can retrieve
I'm using the object_list generic view to quickly list a set of Articles. Each
I have a question about generic list. Assume that I have a database which
In WPF app I have a WCF service which dynamically fills a generic List
I have a generic list List<T> and I want to create a view that
I have a Generic List of objects that I've bound to a custom control.
I have a generic list of objects, for example: List<Photo> and want to convert
I have a Controller/View for a generic list of items, that can be extended
I have a generic list. Some elements of this list belong to a parent
I have a generic list of integer and it contains random numbers. How would

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.