I am trying to use flask-admin, which seems great and easy, but I have a problem.
I have a field in a collection which is defined as a ListField()
, with an implicit type of None
for the list field type. The reason I am not defining a type for the field, is because I am keeping a list of lists, and there is no other elegant way (that I found) to accomplish this with mongoengine.
But flask-admin won't let me define such a field, with an error of ListField "movements" must have field specified for model
.
Is there a way around this?
The reason flask admin needs a field specified is because otherwise the form rendering does not know which type of input to display for it.
For example if it is a choice field, date field, or another list field itself !
You could do something like this:
my_field = db.ListField(field=db.ListField(field=db.StringField()))
The innermost field can be anything, including a EmbeddedDocumentField or IntField, etc.
Also, if you want to continue using ListField
without specifying the field type, you can also ask flask-admin to just treat this as a string by overriding the ModelView
and it will then just give you a text box containing the string:
[ 'a value', 42, { 'A':'B' } ]
So this retains flexibility but reduces structure and makes the validation bad.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With