flask-mongoengine
flask-mongoengine copied to clipboard
only= does not work if model_form is EmbeddedDocument
Example:
class Profile(db.EmbeddedDocument):
login = db.StringField()
pw_hash = db.StringField()
admin = db.BooleanField()
class Users(db.Document):
_id = db.ObjectIdField()
stocks = db.DictField()
profile = db.EmbeddedDocumentField(Profile)
If I use exclude like this, then everything is OK:
from flask_mongoengine.wtf import model_form
form = model_form(Users, exclude=('profile__login'))(request.form)
And the form is generated without the field login.
But if I do like this:
form = model_form(Users, only=('profile__login'))(request.form)
Then nothing is generated. I use flask-mongoengine Version 0.9.5
P.S.: Thanks to maintainers who support this project.
@Alexmod
Thank you for report, and excuse for long answer. In general we are not supporting profile__login
style syntax for form fields include exclude. Fields are not provided in this style by mongoengine.
But for interest, I checked how you got such results.
Not clear what you mean under first statement, with exclude, when you say that everything is OK. I checked in debug logger right on you example, and I still see login field. Maybe you did not found it.
For only
case everything is simple, such field completely not exist under Users, so you got nothing.
I will keep this case in head, but closing this issue, as pretty sure that it will be very hard and dirty to implement. At least for old model_form. I am working on version 2.0.0 with new forms generator, maybe I will include workaround there.