Je souhaite que certains champs d'un modèle créé à l'aide d'une passoire soient facultatifs.
Je suis familier avec l'utilisation de missing=colander.drop
mais cela ne fonctionne que lorsque SchemaNode est défini.
Dans le cas, le champ est défini en utilisant une classe personnalisée, par exemple customeClass = CustomClass()
, comment rendre ceci facultatif?
Ci-dessous l'extrait:Facultatif Colander Champ pour l'objet instancié à l'aide de la classe personnalisée
import colander
class Image(colander.MappingSchema):
url = colander.SchemaNode(colander.String())
width = colander.SchemaNode(colander.Int())
height = colander.SchemaNode(colander.Int())
class Post(colander.MappingSchema):
id = colander.SchemaNode(colander.Int())
text = colander.SchemaNode(colander.String())
score = colander.SchemaNode(colander.Int())
created_time = colander.SchemaNode(colander.Int())
attachedImage = Image() # I want to make this as optional