开发者

Django/GAE anonymous users data

in my application I have per-user models, let开发者_运维知识库 me explain with a simple example:

class Item(db.Model):
master = db.ReferenceProperty(User,collection_name="items")

name = db.StringProperty()
description = db.StringProperty()
value = db.StringProperty()
def __unicode__(self):
    return u"%s"%self.name

So I can store informations on the database only if the user is authenticated. ( well, only if there is an user)

I'm looking for a way to let the anonymous/temporary users to register "personal items" in the session that expires after a certain amount of time.

Any idea?


You could create an Item-like lightweight class and store instances of it in the session. If the user registers later on and you want to sync with what you have in the database, you can pick up what you've stored in the session and convert to the real Item objects (and then save() them).

You can also do it all with the Item objects, leaving master reference as None.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜