简体   繁体   中英

How to save user's daily progress?

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

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.

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.

可以更快地将字典解压缩到Datastore.Model中,或者更不透明地pickle.dumps()将字典转储为字符串,然后通过Gql将其存储。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM