in V1 I was able to recursively add information to the BaseModel.dict method. Is something similar possible in V2?
In V1 this was possible:
from typing import Optional
from pydantic.v1 import BaseModel
class BaseModel2(BaseModel):
def dict(self, **kwargs):
_dict = super().dict(**kwargs)
_dict["__name__"] = self.__class__.__name__
return _dict
class Foo(BaseModel2):
whatever: int
class Bar(BaseModel2):
whenever: Optional[float] = 1.1
foo: Foo
m = Bar(whenever=3.14, foo=Foo(whatever=123))
print(m.dict())
As a result, the dictionary would contain a __name__ for both models, as dict was called recursively.