got it. The populate_obj method of ImageUploadField does ot have effects with pymongo backend because it works with object attributes, while pymongo uses plain dictionaries instead of objects.
I fixed it by simply subclassing ImageUploadField and overloading the populate_obj method to work with dictionaries.
I created a utils.py file including the following:
from flask_admin.form.upload import ImageUploadField as iuf
from werkzeug.datastructures import FileStorage
class ImageUploadField(iuf):
def __init__(self, *args, **kwargs):
super(ImageUploadField, self).__init__(*args, **kwargs)
def populate_obj(self, obj, name):
field = getattr(obj, name, None)
if field:
# If field should be deleted, clean it up
if self._should_delete:
self._delete_file(field)
setattr(obj, name, None)
return
if self.data and isinstance(self.data, FileStorage):
if field:
self._delete_file(field)
filename = self.generate_name(obj, self.data)
filename = self._save_file(self.data, filename)
# update filename of FileStorage to our validated name
self.data.filename = filename
obj[name] = filename # this is the patched line
then in the admin class I import the new subclass instead of the original. The EquipmentViewRoot(ModelView) class now overloads the on_model_change() method where the following instruction
form.photo.populate_obj(model, 'photo')
is executed explicitly, if a photo has been uploaded.
Note: I've not yet tested the fix with the InLineFieldList, photo is now a single ImageUploadField.