当前位置: 首页>>代码示例>>Python>>正文


Python Session.add_all方法代码示例

本文整理汇总了Python中meta.Session.add_all方法的典型用法代码示例。如果您正苦于以下问题:Python Session.add_all方法的具体用法?Python Session.add_all怎么用?Python Session.add_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在meta.Session的用法示例。


在下文中一共展示了Session.add_all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: install

# 需要导入模块: from meta import Session [as 别名]
# 或者: from meta.Session import add_all [as 别名]
def install():
    Base.metadata.create_all(Session().bind)

    data = [
        ("Chicago", "United States", ("60601", "60602", "60603", "60604")),
        ("Montreal", "Canada", ("H2S 3K9", "H2B 1V4", "H7G 2T8")),
        ("Edmonton", "Canada", ("T5J 1R9", "T5J 1Z4", "T5H 1P6")),
        ("New York", "United States", ("10001", "10002", "10003", "10004", "10005", "10006")),
        ("San Francisco", "United States", ("94102", "94103", "94104", "94105", "94107", "94108")),
    ]

    countries = {}
    all_post_codes = []
    for city, country, postcodes in data:
        try:
            country = countries[country]
        except KeyError:
            countries[country] = country = Country(country)

        city = City(city, country)
        pc = [PostalCode(code, city) for code in postcodes]
        Session.add_all(pc)
        all_post_codes.extend(pc)

    for i in xrange(1, 51):
        person = Person(
            "person %.2d" % i,
            Address(street="street %.2d" % i, postal_code=all_post_codes[random.randint(0, len(all_post_codes) - 1)]),
        )
        Session.add(person)

    Session.commit()

    # start the demo fresh
    Session.remove()
开发者ID:simplegeo,项目名称:sqlalchemy,代码行数:37,代码来源:fixture_data.py

示例2: syncdb

# 需要导入模块: from meta import Session [as 别名]
# 或者: from meta.Session import add_all [as 别名]
def syncdb():
    from meta import Base, engine, Session 
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)
    #init data base
    #init perm
    perm_admin = Permission('can_view_admin')
    perm_admin_edit = Permission('can_edit_admin')
    perm_leader = Permission('can_decide')
    #init role
    role_admin = Role('admin')
    role_mem = Role('member')
    role_leader = Role('leader')
    #init type
    utypea = UserType('memberA', 95, 100)
    utypeb = UserType('memberB', 90, 150)
    utypec = UserType('memberC', 85, 200)
    #init user
    user = User('sheimi', 'zhang')
    nuser = User('shaymin', 'zhang')
    session = Session()
    session.add_all([role_admin, role_mem, role_leader, user, nuser])
    session.commit()
    #config relation
    role_admin.perms.append(perm_admin)
    role_leader.perms.append(perm_leader)
    role_leader.perms.append(perm_admin)
    role_admin.perms.append(perm_admin_edit)
    user.roles.append(role_admin)
    nuser.roles.append(role_leader)
    nuser.usertype = utypea
    session.commit()
    
    dt1 = DessertType('Cake')
    dt2 = DessertType('Ice Cream')
    dt3 = DessertType('Fruit')
    session.add_all([dt1, dt2, dt3])
    session.commit()

    d0 = Dessert('Goblet')
    d1 = Dessert('Lemon')
    d2 = Dessert('Buttermilk')
    d3 = Dessert('Chocolate')
    d4 = Dessert('Fruit')
    d5 = Dessert('Valentine')
    d6 = Dessert('Lemon Cake')
    d7 = Dessert('Exotic Fruits')
    d8 = Dessert('Fresh Fruit')
    d9 = Dessert('Chocolate Ice')

    d0.des, d0.type_id = 'This is Description ~~~~~~~', 2
    d1.des, d1.type_id = 'This is Description ~~~~~~~', 3
    d2.des, d2.type_id = 'This is Description ~~~~~~~', 1
    d3.des, d3.type_id = 'This is Description ~~~~~~~', 1
    d4.des, d4.type_id = 'This is Description ~~~~~~~', 3
    d5.des, d5.type_id = 'This is Description ~~~~~~~', 1
    d6.des, d6.type_id = 'This is Description ~~~~~~~', 1
    d7.des, d7.type_id = 'This is Description ~~~~~~~', 3
    d8.des, d8.type_id = 'This is Description ~~~~~~~', 3
    d9.des, d9.type_id = 'This is Description ~~~~~~~', 2

    d0.img = '13569b64-b9e3-4c3a-8a1d-5f794a723d8c'
    d1.img = '83289d63-b49b-4d70-b47a-08d43cdd940e'
    d2.img = 'adc15f11-3f8c-4e33-aba3-a199d2d47da9'
    d3.img = '3426bba5-03e2-4c46-bbd3-dfc7afdbe372'
    d4.img = '4ddc429e-c202-4fbe-8481-59738bc29a88'
    d5.img = '359e9e89-a6f9-44ca-bbef-46e49a490d5a'
    d6.img = '59465deb-26e8-493c-ba40-5c4b96362594'
    d7.img = '59e46ac2-0193-4f57-ae10-3c00a1bf2d3b'
    d8.img = 'c549125d-0f4f-417a-9813-7ea208573681'
    d9.img = '2c70a62e-a09c-4b55-906b-ba7f4bba04e8'
    
    session.add_all([d0, d1, d2, d3, d4, d5, d6, d7, d8, d9])
    session.commit()
    decision = Decision(content="test", title="title")
    decision.add()

    d = Dessert.get_all()
开发者ID:endeavorchan,项目名称:dessert-house,代码行数:80,代码来源:start.py


注:本文中的meta.Session.add_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。