pallets-eco / flask-admin

Simple and extensible administrative interface framework for Flask
https://flask-admin.readthedocs.io
BSD 3-Clause "New" or "Revised" License
5.79k stars 1.57k forks source link

can_view_details does not show EmbeddedDocument List Items [needs to be implemented] #1801

Open bekab95 opened 5 years ago

bekab95 commented 5 years ago

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 ? !

capture

ljluestc commented 1 month 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))