本文整理匯總了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()