Take the 2-minute tour ×

Why is it that when trying to set the value of a field of a model object contained in a list, the value doesn't get set, but when I store the object at that index into a variable, and then try to change it, I am successful? Below is an example of what I mean.

In [64]: profile[0].screen_name = "clutch"

In [65]: profile[0].screen_name

In [66]: p = profile[0]

In [67]: p.screen_name = "clutch"

In [68]: p.screen_name
Out[68]: 'clutch'
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

My guess is that profile in your case is not a list but a QuerySet. So every time you index it, it will execute the query against your database to get the object.

Try this before your code:

profile = list(profile)

That way the query executes and the results are now in a list.

share|improve this answer
I need to not make assumptions about the objects I'm working with ... type is my friend. Thanks! –  IntrepidDude Dec 15 '10 at 2:20
add comment

Your Answer


