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.69k stars 1.56k forks source link

pymongo: integration of get_query into get_list method #2372

Open MihailMiller opened 11 months ago

MihailMiller commented 11 months ago

In the current pymongo implementation of the get_list method in the ModelView class, the default query is defined as {}. There is no way to override this query without overriding get_list, which makes the code less maintainable. For example, the sqla contribution allows you to override the get_query when subclassing the ModelView.

I propose to include a get_query call in the get_list method. This change would allow developers to override only the get_query method and pre-filter the database so that only relevant results are displayed according to the specific parameters of the use case.

Proposed change:

Revise get_list in ModelView to call get_query:

def get_query():
    return {}

def get_list(self, page, sort_column, sort_desc, search, filters, execute=True, page_size=None):
    query = self.get_query()
    # continue existing logic...

I will be happy to make a pull request if you would like to integrate this into the pymongo contribution.