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 6205575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:17:56+00:00 2026-05-24T05:17:56+00:00

I have run into an odd problem in my django application where a for

  • 0

I have run into an odd problem in my django application where a for loop is skipping every other item. I have take a returned queryset and list()ed to iterate over. The point of doing this is to remove items that are inside another list that is getting passed to the view via a POST variable. This view is an ajax request and returns a JSON list of items needed to be pushed to the page. upon the next request, the page passes the list of IDs of objects that are already on the page, so I can remove those from the queryset and pass back only new ones. I put several print statements throughout the problem portion of the code and figured out that the on the first request from the page, the list comes into the page empty because there aren’t any displayed. The query runs and returns all the results which then get displayed on the page. On the second request, the list comes into the page with all of the id’s, and this is where the problem occurs: As I loop through the queryset, checking to see if the id’s are in the list, it only iterates over the odd values (which are removed) and returns a list of the even id’d objects to get displayed a second time on the page.

code:

items = list(listobj.getItems())
temp = items
print "Item List: ", temp
print "Rendered List: ", request.POST['rendered'].split(',')
for item in temp:
    print "Item ID: ", str(item.id)
    print "Rendered List: ", request.POST['rendered'].split(',')
    if str(item.id) in request.POST['rendered'].split(','):
        items.remove(item)
        print "Removed Item: ", item.id
print "Unrendered Items: ", [item.id for item in items]

Results:

    [02/Aug/2011 20:17:25] "GET /list/list HTTP/1.1" 200 6256
Item List:  [<Item: Item object>, <Item: Item object>, <Item: Item object>, <Item: Item object>, <Item: Item object>, <Item: Item object>, <Item: Item object>, <Item: Item object>, <Item: Item object>]
Rendered List:  [u'']
Item ID:  1
Rendered List:  [u'']
Item ID:  2
Rendered List:  [u'']
Item ID:  3
Rendered List:  [u'']
Item ID:  4
Rendered List:  [u'']
Item ID:  5
Rendered List:  [u'']
Item ID:  6
Rendered List:  [u'']
Item ID:  7
Rendered List:  [u'']
Item ID:  8
Rendered List:  [u'']
Item ID:  9
Rendered List:  [u'']
Unrendered Items:  [1, 2, 3, 4, 5, 6, 7, 8, 9]
[02/Aug/2011 20:17:25] "POST /items/ HTTP/1.1" 200 528
Item List:  [<Item: Item object>, <Item: Item object>, <Item: Item object>, <Item: Item object>, <Item: Item object>, <Item: Item object>, <Item: Item object>, <Item: Item object>, <Item: Item object>]
Rendered List:  [u'1', u'2', u'3', u'4', u'5', u'6', u'7', u'8', u'9']
Item ID:  1
Rendered List:  [u'1', u'2', u'3', u'4', u'5', u'6', u'7', u'8', u'9']
Removed Item:  1
Item ID:  3
Rendered List:  [u'1', u'2', u'3', u'4', u'5', u'6', u'7', u'8', u'9']
Removed Item:  3
Item ID:  5
Rendered List:  [u'1', u'2', u'3', u'4', u'5', u'6', u'7', u'8', u'9']
Removed Item:  5
Item ID:  7
Rendered List:  [u'1', u'2', u'3', u'4', u'5', u'6', u'7', u'8', u'9']
Removed Item:  7
Item ID:  9
Rendered List:  [u'1', u'2', u'3', u'4', u'5', u'6', u'7', u'8', u'9']
Removed Item:  9
Unrendered Items:  [2, 4, 6, 8]
[02/Aug/2011 20:17:55] "POST /items/ HTTP/1.1" 200 252
  • 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-24T05:17:57+00:00Added an answer on May 24, 2026 at 5:17 am

    temp and items refer to the same object, so when you do items.remove() you’re also modifying temp. You probably want to do temp = items[:] to copy the values of the items list.

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

Sidebar

Related Questions

This is an odd thing I've just run into. I have a web application
I have run into a rather odd problem, my app crashes if I try
I have run into a common, yet difficult problem. I do not use Photoshop
I have run into a bit of a tricky problem in some C++ code,
I have run into this problem before but never quite solved it. I have
I have run into a problem trying to modify a form I myself have
I have run into a bit of a problem here: I had a problem-specific
I've run into something odd, here, and I'm at a loss -- I have
I'm using PuTTY to log into a Debian server. I have this odd problem
I've run into an odd problem with attached properties where when I assign the

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.