модель SQLModel. Эти модели имеют отношение многие ко многим. Я создал промежуточную модель, чтобы соединить эти две модели. Я хочу реализовать его без прямого импорта моделей, чтобы избежать возможного циклического импорта в будущем.
Код: Выделить всё
# documents/models.py
class Document(SQLModel, table=True):
__tablename__ = "documents"
id: int | None = Field(primary_key=True, default=None)
name: str = Field(max_length=128)
vehicles: list["Vehicle"] = Relationship(back_populates="documents", link_model=VehicleDocument)
class VehicleDocument(SQLModel, table=True):
__tablename__ = "vehicle_documents"
id: int | None = Field(primary_key=True, default=None)
vehicle_id: int = Field(foreign_key="vehicles.id")
document_id: int = Field(foreign_key="documents.id")
# vehicles/models.py
class Vehicle(VehicleBase, table=True):
__tablename__ = "vehicles"
id: int | None = Field(primary_key=True, default=None)
documents: list["Document"] = Relationship(back_populates="vehicles", link_model=VehicleDocument)
Код: Выделить всё
link_model="VehicleDocument"Код: Выделить всё
link_model="documents.models.VehicleDocument"Код: Выделить всё
link_model="documents.models.vehicle_documents"
"NoInspectionAvailable: Нет система проверки доступна для объекта типа "
Есть ли другой способ соединения этих моделей?
Подробнее здесь: https://stackoverflow.com/questions/792 ... rts-in-fas
Мобильная версия