Вот соответствующие файлы: p>
src/schemas/user.py
Код: Выделить всё
from typing import List
from pydantic import BaseModel
from src.schemas.blog import ShowBlog # Import causing circular dependency
class ShowUser(BaseModel):
username: str
email: str
blogs: List[ShowBlog]
class Config:
from_attributes = True
class User(BaseModel):
username: str
email: str
password: str
Код: Выделить всё
from pydantic import BaseModel
from src.schemas.user import ShowUser # Import causing circular dependency
class Blog(BaseModel):
title: str
description: str
user_id: int
class ShowBlog(BaseModel):
id: int
title: str
description: str
written_by: ShowUser
class Config:
from_attributes = True
Код: Выделить всё
ImportError: cannot import name 'ShowBlog' from partially initialized module 'src.schemas.blog' (most likely due to a circular import)
Подробнее здесь: https://stackoverflow.com/questions/790 ... tic-models