Hi,
Is it possible to use a dict type as a Model instance attribute?
I can't seem to make it work correctly. Using strings as a model
instance attribute seems to be fine, but when I assign values to an
element of a model's arbitrary dict attribute, I can't seem to
reference the correct Model instance.
See below (you can try this in your console)
---
from google.appengine.api import users
from google.appengine.ext import webapp, db
# Say hello to the current user
class A(db.Model):
someProp = db.StringProperty()
someStrVar = ''
someDictVar = {}
db.delete( A.all() )
A(someProp='Hello Me').put()
A(someProp='Hello You').put()
results = A.all().fetch(10)
#print len(results)
i=0
print 'As expected: \n'
for i in [0,1]:
results[i].someStrVar = 'someStrVar=' + str(i)
results[i].someDictVar['x'] = 'someDictVar=' +str(i)
print results[i].someProp
print results[i].someStrVar
print results[i].someDictVar['x']
print ''
print '\nRather unexpected results:\n'
for i in [0,1]:
print results[i].someProp
print results[i].someStrVar
print results[i].someDictVar['x']
---
Produces the results:
As expected:
Hello Me
someStrVar=0
someDictVar=0
Hello You
someStrVar=1
someDictVar=1
Rather unexpected results:
Hello Me
someStrVar=0
someDictVar=1 ##Here's the error. THIS SHOULD BE: someDictVar=0 ##
Hello You
someStrVar=1
someDictVar=1
---
Notice that the property and string att are correct in both
iterations. But the dict attribute isn't.
Would appreicate any help at all.
Thanks,
Ray
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---