コード例 #1
0
def insert_media_types():

    # delete records (if any)
    MediaTypeModel.objects().delete()

    # loop through records
    for media_type in media_types:
        # create record
        media_type_model = MediaTypeModel(**media_type)
        # insert record
        media_type_model.save()
コード例 #2
0
def insert_events():

    # delete records (if any)
    EventModel.objects().delete()

    # loop through records
    for event in events:
        # find media_type record
        event['media_type'] = MediaTypeModel.objects(
            media_type=event['media_type']).first()
        # find block record
        event['block'] = BlockModel.objects(
            block_number=event['block']).first()['block_id']
        # create record
        event_model = EventModel(**event)
        # insert record
        event_model.save()