I'm trying to get parent document (mongoengine.Document
) of an EmbeddedDocument
and, as suggested here I'm using self._instance
.
I'm trying to get this attribute in post_init
method, but it doesn't exist and raises this exception: Field 'image' - 'FileEmbeddedDocument' object has no attribute '_instance'
How can I get the _instance
attribute in post_init? Or is there a better way to get the parent document?
I'm using
- flask==1.1.4
- flask-mongoengine=1.0.0
- mongoengine==0.23.1
class FileEmbeddedDocument(EmbeddedDocument):
name = StringField()
@classmethod
def post_init(cls, sender, document, **kwargs):
current_app.logger.debug(document._instance)
signals.post_init.connect(FileEmbeddedDocument.post_init, sender=FileEmbeddedDocument)
class Company(Document):
name = StringField(required=True, min_length=3)
image = EmbeddedDocumentField(FileEmbeddedDocument, null=True, default=None)