Open
Description
Checklist
- There are no similar issues or pull requests for this yet.
Is your feature related to a problem? Please describe.
I want to be able to filter by specific column.
Describe the solution you would like.
Filtering by specific columns, having dropdowns for foreign keys or enums, yes or no options for booleans, and text inputs for varchars, etc., similar to Django Admin Filtering.
Describe alternatives you considered
This could be a path to start working with this:
Add filter filter_by
as an array of string making refernce to the colums:
class UserAdmin(ModelView, model=User):
filter_by = ["state_id"]
Declare the property in ModelView:
class ModelView(BaseView, metaclass=ModelViewMeta):
...
filter_by: ClassVar[Optional[List[str]]] = []
...
Get filters from query params, in the list endpoint:
@login_required
async def list(self, request: Request) -> Response:
"""List route to display paginated Model instances."""
...
filters = {}
for col in model_view.filter_by:
if col in request.query_params:
filters[col] = request.query_params[col]
# send filters to list method of the model_view instance
pagination = await model_view.list(page, page_size, search, sort_by, sort, filters)
The next steps would be to actually filter for these fields in the list method of the ModelView and render the appropriate forms based on the active filters.
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels