0

My use case forces me to build something like a recursive model. For example, if I want to model file and folder from an OS system:

A folder can contain multiple folder and files, and the same apply recursively for folders inside a folder. I try to represent this in Python, I am using pydantic for modeling my schema :

from typing import List
from pydantic import BaseModel

class File(BaseModel):
     name: str

class Folder(BaseModel):
     folders : List[Folder]
     files: List[File]
     name: str

I am kind of struggle to represent the logic that a folder can contain multiple folder, and so on and so on. Thank you for your help.

Pdeuxa
  • 651
  • 7
  • 27

0 Answers0