Iteration on the fetched list of model instances is not expensive.
What IS expensive is calling put() 100 times.
I suggest changing your code to this:
results = Foo.all.filter...fetch(100)
# Need to perform some operation on these 100 records
for r in results:
r.column -=1
# Save all models at once.
db.put(results)
# Now render results using template (will have to loop again).
path = os.path.join(os.path.dirname(__file__), 'Foo.html')
template_values = {
'r': results,
}
self.response.out.write(template.render(path, template_values))
On Sep 20, 1:55 pm, Ethan <[EMAIL PROTECTED]> wrote:
> I need to do something like this. It looks like in order to a) perform
> some operation on my 100 records and update the datastore and b)
> render the 100 records in a template, that I have to iterate through
> the records twice.
>
> Is this the only way to do this if I want to use a template? Is there
> a more efficient way?
>
> results = Foo.all.filter...fetch(100)
>
> # Need to perform some operation on these 100 records
> for r in results:
> r.column -=1
> r.put()
>
> # Now render results using template (will have to loop again).
> path = os.path.join(os.path.dirname(__file__), 'Foo.html')
>
> template_values = {
> 'r': results,
> }
>
> self.response.out.write(template.render(path, template_values))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" 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/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---