Files
stu/dao/teacher_course_dao.py
T
2026-09-22 17:29:35 +08:00

25 lines
707 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from model.teacher_model import TeacherCourse
def add_teacher_course_dao(t,db):
try: #判断是都已存在
r = db.query(TeacherCourse).filter(TeacherCourse.teacher_id==t['teacher_id']).first()
if r:
return None #已存在,交给上层判断
obj = TeacherCourse(**t)
db.add(obj)
db.commit()
db.refresh(obj) #拿回自增id,create_time等
return obj
except Exception:
db.rollback()
return False
def get_teacher_course_dao(teacher_id=None,db=None):
q = db.query(TeacherCourse)
if teacher_id:
q = q.filter(TeacherCourse.teacher_id==teacher_id)
return q.all() #返回ORM对象列表