0

I have an unknown variable that I want to use as a datastore property name. I'm using Expando, as I know you can dynamically create properties without first declaring them in the db class, however I am unable to do this as the property names are not known. I get the error: 'StoreNames' object does not support item assignment. Is there any way around this?

class StoreNames(db.Expando):
  index = db.FloatProperty()

name = "unknown"

value = "something"

store = StoreNames()

store[name] = value
store.index = 0
Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
AshClarke
  • 2,990
  • 5
  • 21
  • 27
  • 1
    Use the setattr() method as described here: [How to create dynamic fields in Google App Engine expando class?][1] [1]: http://stackoverflow.com/questions/4160752/how-to-create-dynamic-fields-in-google-app-engine-expando-class – Brent Washburne Jun 08 '13 at 05:11

1 Answers1

0

Solved by using the following code:

class StoreNames(db.Expando):
  index = db.FloatProperty()

name = "unknown"

value = "something"

store = StoreNames()

setattr(db, name, value)

I would have answered earlier but Stackoverflow wouldn't let me. Thanks Brent Washburne

AshClarke
  • 2,990
  • 5
  • 21
  • 27