I want to create a Pydantic class with a constructor that does some math on inputs and set the object variables accordingly:
class PleaseCoorperate(BaseModel):
self0: str
next0: str
def __init__(self, page: int, total: int, size: int):
# Do some math here and later set the values
self.self0 = ""
self.next0 = ""
But when I try to actually use that class page = PleaseCoorperate(0, 1, 50)
I get this error:
main_test.py:16:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
main.py:46: in __init__
self.self0 = ""
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E AttributeError: __fields_set__
What is happening here? Can I not use constructors on a Pydantic
class?