2011-04-12 31 views

回答

2

你可以一个角色属性添加到您的用户类:

class MyUser(db.Model): 
    roles = db.ListProperty(db.Key) 

class Role(db.Model): 
    ... 

然后,当你想知道用户是否可以做一些事情,做这样的事情:

if required_role in current_user.roles: 
    do_the_thing() 
else: 
    warn_sternly() 

你需要建模的是谁是什么角色。这是一种多对多的关系(至少在大多数应用中)。这是实现这种关系的一种方式,但还有其他方式,可能更适合您的情况。以下是一个关于App Engine中关系建模建议的页面:https://developers.google.com/appengine/articles/modeling

相关问题