Modifyl Build () Methode eines polyfaktorischen Modellors und stellt sicher, dass fehlende Felder standardmäßig leere WöPython

Python-Programme
Anonymous
 Modifyl Build () Methode eines polyfaktorischen Modellors und stellt sicher, dass fehlende Felder standardmäßig leere Wö

Post by Anonymous »

Ich habe ein pedantisches Modell wie unten: < /p>

Code: Select all

class ModelA(BaseModel):
field1: str
field2: Optional[float]
field3: Optional[Dict[str, Dict[str, float]]] = {}
field4: Optional[Dict[str, Dict[str, float]]] = {}
field5: Optional[Dict[str, Dict[str, float]]] = {}
< /code>
Ich möchte eine Modellfabrik schreiben: < /p>
class ModelAFactory(ModelFactory[Any]):
__model__ = ModelA

@classmethod
def build(cls, **kwargs):
"""Use this method to assign default value as {} for fields 3,4 and 5. For other fields model factory can assign random values."""

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post