How do I assign a ListProperty with Google App Engine?
name = self.request.get("name")
description = self.request.get("description")
list = '''insert code here'''
I want list to work like a dictionary, is this possible with Google App Engine, if so, how:
[wordone : score; wordtwo : score; wordthree : score]
^I want the list property to store some data like this, how is this possible?
You actually won’t be able to store a true dictionary as type in a
ListProperty(it only supports datastore property types, of whichdictis not one), so you won’t be able to get the behavior you’re looking for. Will all of the data be the same (i.e. each element represents a word score)? Assuming storing each word as its own property on the model doesn’t make sense, one ‘dirty’ solution would be to make aListPropertyof typestr, and then append the word and score as separate elements. Then, when you searched for a word in the list, you would return the value at the index position of the word + 1. That would looks something like:You could then add words like:
You could then query for a particular entity and then examine its
word_listproperty (a list), looking for your target word and returning the element one position after it.More convoluted suggestion
However if that isn’t an option, you could look into creating another model (let’s say
WordScore) that looked something like:Then, whenever you needed to add a new score, you would create a
WordScoreinstance, fill out the properties and then assign it to the proper entity. I haven’t tested any of this, but the idea would be something like:You could then pull out the score for
dogfor ‘Someone’ by doing something like this (again, completely untested for now – be warned 🙂 ):