is it possible to create a pydantic model form an instance of a pydantic model, so that the values are maintained ? Something like this:
from pydantic import create_model,BaseModel,Field
from typing import Optional
class ExampleModel(BaseModel):
some_text: str
optional_number: Optional[float]
instance=ExampleModel(some_text="foo")
dynamic_Model=create_model("Parameters",__config__=instance.Config)
dyn_instance=dynamic_Model()
print(instance)
print(dyn_instance) #this has no attributes so it's an empty line
print("Is it equal ? "+ str(dyn_instance == instance)) #can this be true?
If you wonder about the use case. I want to build an web-app with Streamlit and Streamlit-pydantic. The later reders an UI-inputmask from a pydantic model like this:
instance_of_pydantic_model=sp.pydantic_form(model=pydanticModel, key='some key')
This leads in a multi-page application to the problem, that the Input_mask will not display any of the user input after switch to another page an back.