On Wed, 2007-04-18 at 17:22 +0100, Merric Mercer wrote:
> I'm getting, what seems to me, an inconsistency.
> Here's a simplified example:
> 
> 
>  >>qs=Mymodel.objects.all()
>  >>for i in qs:
>              setattr(i,"firstname","merric")
> 
> This  works on:-
> 
>  >>qs[0].firstname
>  >>merric
> 
> It also works in the template:-
> 
> {% for i in qs %} {{ i.firstname }}  {% endfor %}
> 
> so I don't understand why this doesn't seem to work after I've set the 
> new attribute:-
> 
>  >> for i in qs:
>            print i.name
>  >> Attribute Error 'QuerySet' object has no attribute 'merric'.
> 
> Am I doing something fundamentally wrong?   If not this seems rather 
> inconsistent.   If I can iterate through an altered QuerySet in my 
> template why can't I do
> so in the code?

Something more than what you think is going on here. This sort of simple
example (iterating through a queryset adding an attribute, then
iterating again to read the attribute) works perfectly for me. I just
tested it on half a dozen different models without problems.

So you might need to do some looking around to work out what is special
about your models. Or look at the details you might have trimmed to make
the example simpler and start putting them back in one by one.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to