Embedded documents fields¶
Work with embedded documents.
class EDoc(EmbeddedDocument):
i = fields.IntegerField()
class Doc(Document):
__collection__ = 'docs'
edoc = EmbeddedDocumentField(EDoc)
doc = Doc()
doc.edoc = EDoc()
doc.edoc.i = 13
db.insert(doc)
-
class
yadm.fields.embedded.
EmbeddedDocumentField
(embedded_document_class, *, auto_create=True, **kwargs)¶ Field for embedded objects.
Parameters: - embedded_document_class (EmbeddedDocument) – class for embedded document
- auto_create (bool) – automatic creation embedded document from access
-
copy
()¶ Return copy of field.
-
get_if_attribute_not_set
(document)¶ Call if key not exist in document.
If auto_create is True, create and return new embedded document. Else AttributeError is raised.
-
class
yadm.fields.embedded.
SimpleEmbeddedDocumentField
(fields, *, auto_create=True, **kwargs)¶ Field for simply create embedded documents.
Usage:
- class Doc(Document):
- embedded = SimpleEmbeddedDocumentField({
- ‘i’: IntegerField(), ‘s’: StringField(),
})
-
class
yadm.fields.embedded.
TypedEmbeddedDocumentField
(type_field=None, types=None, **kwargs)¶ Field for embedded document with variable types.
Parameters: - type_field (str) – name of field in embedded document for select type
- types (dict) – map of type names to embedded document classes