【发布时间】:2016-05-26 16:55:03
【问题描述】:
我已在auth_user 表中添加了uuid 字段,并将该字段的default 值设置为web2py_uuid(),如下所示:
模块:
class User_Custom(Base):
def __init__(self, ...):
...
auth.settings.extra_fields['auth_user']= [
Field('uuid', type='string', default = web2py_uuid(),
readable=False, writable=False, label=current.T('UUID')),
]
我正在使用一些自定义函数来填充我的数据库,并发现auth_user 中的每个用户都以相同的uuid 值结束。
`populate.py' 模型文件:
def create_user():
user_dict = dict(
first_name = random.choice(FIRST_NAMES),
last_name = random.choice(LAST_NAMES),
email = ...,
password = ..,
)
return db.auth_user.insert(**user_dict)
def create_profile(count = 100):
for idx in range(count):
user_id = create_user()
# create a bunch of data for tables referenced by db.auth_user
我的印象是,以上述方式创建的每个用户都会有一个唯一的 uuid(即,每次创建用户时都会调用 web2py_uuid,并且每次都会生成唯一的输出)。 uuid 值在由单个调用create_profile() 生成的所有用户之间是一致的预期行为吗?如上例中使用default参数时,有没有办法保证每个用户都有一个唯一的uuid值?
【问题讨论】:
标签: web2py