I've been working with Flask and MongoEngine, and I am having trouble when trying to save an object because of a ReferenceField.
This is what my model looks like:
class User(UserMixin, db.Document):
first_name = db.StringField(max_length=255, required=True)
last_name = db.StringField(max_length=255, required=True)
email = db.StringField(max_length=255)
class Post(db.Document):
description = db.StringField(max_length=255, required=True)
inserted_at = db.DateTimeField(default=datetime.datetime.now, required=True)
tags = db.ListField(db.EmbeddedDocumentField('Tag'))
comments = db.ListField(db.EmbeddedDocumentField('Comment'))
user = db.ReferenceField('User')
This is how I create the Post object:
user = User.objects.filter(id=current_user.id).first()
post = Post(
description = request.json["description"],
user = user
)
I have also tried:
user = current_user._get_current_object()
But I keep getting:
InvalidDocument: Cannot encode object: <User: User object>
Any ideas on what's going on?
Thanks!