コード例 #1
0
def _load_fake_data(session: Session):
    lessons_names = ['Математика', 'Программирование', 'Философствуем за кружечкой пенного',
                     'Алгоритмы и структуры данных', 'Линейная алгебра', 'Мат. статистика',
                     'Физкультура']
    group1 = Group(group_name='1-МДА-7')
    group2 = Group(group_name='1-МДА-9')
    session.add(group1)
    session.add(group2)

    for key, it in enumerate(lessons_names):
        lesson = Lesson(lesson_title=it)
        lesson.groups.append(group1)
        if key % 2 == 0:
            lesson.groups.append(group2)
        session.add(lesson)

    faker = Faker('ru_RU')
    group_list = [group1, group2]
    session.commit()

    for _ in range(50):
        full_name = faker.name().split(' ')
        age = faker.random.randint(16, 25)
        address = faker.address()
        group = faker.random.choice(group_list)
        student = Student(full_name, age, address, group.id)
        session.add(student)

    session.commit()
    session.close()
コード例 #2
0
def create_data(session: Session):
    department1_id = uuid.uuid4().hex
    department2_id = uuid.uuid4().hex
    department1 = Department(id=department1_id,
                             title='Биология и Общая генетика')
    department2 = Department(id=department2_id, title='Биотехнология')
    session.add(department1)
    session.add(department2)

    mypath = "C:/Users/Andrey/Pictures/PNG"
    onlyfiles = listdir(mypath)
    added_objects = []

    for obj in onlyfiles:
        splited_obj = obj.split('_')
        if splited_obj[0] in added_objects:
            continue
        obj_id = uuid.uuid4().hex
        new_object = Object(id=obj_id,
                            title=splited_obj[0],
                            department_id=department1_id)
        session.add(new_object)
        for fl in onlyfiles:
            splited_fl = fl.split('_')
            zoom_fl = splited_fl[1].split('.')
            if fl.find(splited_obj[0]) != -1:
                fl_id = uuid.uuid4().hex
                new_file = File(id=fl_id,
                                type='image',
                                url=fl,
                                zoom=zoom_fl[0],
                                object_id=obj_id)
                session.add(new_file)
        added_objects.append(splited_obj[0])

    session.commit()
    session.close()