Skip to content

Commit 9b08745

Browse files
sheldyggaminalaee
andauthored
Add category_icon (#848)
Co-authored-by: Amin Alaee <[email protected]>
1 parent ab2d48a commit 9b08745

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

docs/api_reference/model_view.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- name_plural
77
- icon
88
- category
9+
- category_icon
910
- column_labels
1011
- can_create
1112
- can_edit

docs/configurations.md

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ The metadata for the model. The options are:
7777
* `name_plural`: Display plural name for this model. Default value is class name + `s`.
7878
* `icon`: Icon to be displayed for this model in the admin. Only FontAwesome and Tabler names are supported.
7979
* `category`: Category name to display group of `ModelView` classes together in dropdown.
80+
* `category_icon`: Category icon to display.
8081

8182
!!! example
8283

@@ -86,6 +87,7 @@ The metadata for the model. The options are:
8687
name_plural = "Users"
8788
icon = "fa-solid fa-user"
8889
category = "accounts"
90+
category_icon = "fa-solid fa-user"
8991
```
9092

9193
## List page

sqladmin/application.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ async def test_page(self, request: Request):
266266

267267
def _build_menu(self, view: ModelView | BaseView) -> None:
268268
if view.category:
269-
menu = CategoryMenu(name=view.category)
269+
menu = CategoryMenu(name=view.category, icon=view.category_icon)
270270
menu.add_child(ViewMenu(view=view, name=view.name, icon=view.icon))
271271
self._menu.add(menu)
272272
else:

sqladmin/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ async def test_page(self, request: Request):
183183
category: ClassVar[str] = ""
184184
"""Category name to group views together."""
185185

186+
category_icon: ClassVar[str] = ""
187+
"""Display icon for category in the sidebar."""
188+
186189

187190
class ModelView(BaseView, metaclass=ModelViewMeta):
188191
"""Base class for defining admnistrative behaviour for the model.

0 commit comments

Comments
 (0)