Open bekab95 opened 5 years ago
from flask_admin.contrib.mongoengine import ModelView
from flask_admin.form import EmbedField
from flask import Markup
class UserModelView(ModelView):
def _list_embedded(self, value):
if value:
return Markup('<br>'.join(f'{addr.street}, {addr.city}' for addr in value))
return ''
column_formatters = {
'addresses': _list_embedded
}
def _get_embedded_columns(self):
return ['addresses']
def _get_column_names(self):
return super()._get_column_names() + self._get_embedded_columns()
def scaffold_list(self):
return super().scaffold_list() + [EmbedField('addresses')]
# Register your view
admin.add_view(UserModelView(User))
Is it possible to display EmbeddeDocuments in view_details ? I think this needs implement, I can make PR but base code is not simple and there is only_columns in code and it may also have embedded_columns ? !