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


Python Event.rooms方法代码示例

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


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

示例1: Room

# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import rooms [as 别名]
for room_info in room_infos:
    room = Room()
    room.room_name = room_info[0]
    room.room_sq_ft = room_info[1]
    room.room_capacity = room_info[2]
    if room_info[3]:
        room.room_group = db.session.query(RoomGroup).\
            filter(RoomGroup.room_group_name == room_info[3]).first()
    db.session.add(room)

db.session.commit()

# Assign a random room to each event.
events = Event.query.all()
rooms = Room.query.all()
for event in events:
    # Randomly select a room for this event
    random_rooms = random.sample(rooms, random.randrange(1,2))

    # If the room has a room group, randomly select
    # 0 to 1 more rooms from that group for this event.
    if random_rooms[0].room_group:
      another_room = random.choice(rooms)
      if random_rooms[0] != another_room and random_rooms[0].room_group == another_room.room_group:
        random_rooms.append(another_room)

    event.rooms = random_rooms

# Commit the test data to the database.
db.session.commit()
开发者ID:MattArnold,项目名称:CREM,代码行数:32,代码来源:add_testdata.py


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