Код: Выделить всё
sub_department.pyКод: Выделить всё
from sqlalchemy import Column, String, Integer, ForeignKey
from sqlalchemy.orm import relationship
from src.db import Base
class SubDepartment(Base):
__tablename__ = 'sub_department'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String, index=True, unique=True)
department_id = Column(Integer, ForeignKey('department.id'))
department = relationship('Department', back_populates='sub_departments')
consultation_appointment = relationship('ConsultationAppointment', back_populates='sub_department')
Код: Выделить всё
class Department(Base):
__tablename__ = 'department'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String, index=True, unique=True)
sub_department = relationship('SubDepartment', back_populates='department')
doctor = relationship("Doctor", back_populates='departments')

если я импортирую всю модель в
Код: Выделить всё
main.pyПодробнее здесь: https://stackoverflow.com/questions/786 ... in-fastapi