本文整理汇总了Python中model.DBSession.save方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.save方法的具体用法?Python DBSession.save怎么用?Python DBSession.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.DBSession
的用法示例。
在下文中一共展示了DBSession.save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_database
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import save [as 别名]
def setup_database():
init_model(engine)
teardownDatabase()
elixir.setup_all(True)
# Creating permissions
see_site = Permission()
see_site.permission_name = u'see-site'
see_site.description = u'see-site permission description'
DBSession.save(see_site)
edit_site = Permission()
edit_site.permission_name = u'edit-site'
edit_site.description = u'edit-site permission description'
DBSession.save(edit_site)
commit = Permission()
commit.permission_name = u'commit'
commit.description = u'commit permission description'
DBSession.save(commit)
# Creating groups
admins = Group()
admins.group_name = u'admins'
admins.display_name = u'Admins Group'
admins.permissions.append(edit_site)
DBSession.save(admins)
developers = Group(group_name=u'developers',
display_name=u'Developers Group')
developers.permissions = [commit, edit_site]
DBSession.save(developers)
trolls = Group(group_name=u'trolls', display_name=u'Trolls Group')
trolls.permissions.append(see_site)
DBSession.save(trolls)
# Plus a couple of groups with no permissions
php = Group(group_name=u'php', display_name=u'PHP Group')
DBSession.save(php)
python = Group(group_name=u'python', display_name=u'Python Group')
DBSession.save(python)
# Creating users
user = User()
user.user_name = u'rms'
user.password = u'freedom'
user.email_address = u'[email protected]'
user.groups.append(admins)
user.groups.append(developers)
DBSession.save(user)
user = User()
user.user_name = u'linus'
user.password = u'linux'
user.email_address = u'[email protected]'
user.groups.append(developers)
DBSession.save(user)
user = User()
user.user_name = u'sballmer'
user.password = u'developers'
user.email_address = u'[email protected]'
user.groups.append(trolls)
DBSession.save(user)
# Plus a couple of users without groups
user = User()
user.user_name = u'guido'
user.password = u'phytonic'
user.email_address = u'[email protected]'
DBSession.save(user)
user = User()
user.user_name = u'rasmus'
user.password = u'php'
user.email_address = u'[email protected]'
DBSession.save(user)
DBSession.commit()