Beispiel #1
0
def create_stu_gra():
    stu = Students()
    stu.s_name = '李哥'
    stu.s_age = 27
    stu.s_g = 3
    stu.save()
    return '一对多一个学生添加成功'
Beispiel #2
0
def create_stus_gra():
    names = ['老王', '55开', 'uzi', '大哥', '麻辣香锅', 'god', 'wawa']
    stu_list = []
    i = 1
    for name in names:
        stu = Students()
        stu.s_name = name
        stu.s_g = i % 5 + 1
        i += 1
        stu_list.append(stu)
    db.session.add_all(stu_list)
    db.session.commit()
    return '一对多批量学生添加成功'