Filters and Saved Views
Just like Django’s list_filter, SmartBase supports adding filters based on model fields, including related fields. Filters are automatically displayed in the UI, and you can stack multiple filters together to narrow down your data.
Saved Views
A powerful upgrade that SmartBase Admin allows users to save filtered views with their preferred column layout, filters, and sorting. This is helpful when working with large datasets or recurring workflows.
For example, administrator can save a view for only Active products
These saved views are accessible from the UI and persist across sessions, making the admin panel more user-friendly and workflow-driven.
💡Usage example: Saved Views
Apply your preffered filters using the sidebar or column filters. Click the “Save View” button in the top-right corner of the list view interface.
A dialog will appear prompting you to enter a name for the view.
Once saved, the view will appear in the list of available views, allowing you to easily switch between different filter and display configurations.
Predefined filtered views
SmartBase Admin allows you to define custom filtered views directly in your admin class using the sbadmin_list_view_config attribute. These views are especially useful for frequently used filter combinations, allowing quick access from the UI.
💡Usage example: Predefined filters
Here's an example of how to define a predefined view that shows only inactive products:
- Code
- Result
@admin.register(Product, site=sb_admin_site)
class ProductSBAdmin(SBAdmin):
...
sbadmin_list_view_config = [
{
"name": _("Inactive"),
"url_params": {
"filterData": {"is_active": False}
},
}
]
...
Advanced Filters
Advanced Filters allow you to create powerful queries across different fields for more precise data filtering.
Enable Advanced Filters globally
To enable advance filters globally, you have to set filter version in your SBAdminRoleConfiguration
- Code
- Result
class BaseConfiguration(SBAdminRoleConfiguration):
filters_version = FilterVersions.FILTERS_VERSION_2,
Enable Advanced Filters only for selected views
You can enable Andvanced Filters for view by setting filters_version = FilterVersions.FILTERS_VERSION_2
parameter in your SBAdmin view.
@admin.register(Purchase, site=sb_admin_site)
class PurchaseSBAdmin(SBAdmin):
model = Purchase
filters_version = FilterVersions.FILTERS_VERSION_2
...