views:

72

answers:

3

Hello,

I'm building an app where I'm trying to store the user's progress on a game. I want to be able to store the score of a player on a daily basis, and then retrieve the day's score when I look for the date.

I wanted to store a dictionary in the database, with keys being the dates when the user played and the values being the score, but I can't store a dictionary with GAE.

How can I do? I'm using google appengine with python

Thanks

A: 

A dictionary can be transformed back and forth between a list-of-tuples.

aTupleOfTuples= tuple( someDict.items() )

aDict = dict( aTupleOfTuples )

This is probably what you're looking for.

S.Lott
I think the user is struggling more with how to represent this in the app engine datastore.
Peter Recore
A: 

Either unpack the dictionary into a Datastore.Model or more quickly, but more opaquely pickle.dumps() the dictionary into a string and store that via Gql.

msw
It's not a Gql.Model. It's a Datastore model. GQL is just a layer on top of the datastore for people who don't want to learn the Query API.
Nick Johnson
Pardon my being loose with my nomenclature, no offense intended; fixed.
msw
+3  A: 

I think an easy way would be to create a db.Model to represent an entry in the dictionary you were originally thinking about. Just to sketch it out, what I mean is something similar to this:

class DailyProgress(db.Model):
    date = db.DateTimeProperty(auto_now_add=True)
    score = db.IntegerProperty()

Then, you could store a list of those for each of your users.

Lyudmil