Skip to content

Commit

Permalink
Add category_icon (#848)
Browse files Browse the repository at this point in the history
Co-authored-by: Amin Alaee <[email protected]>
  • Loading branch information
sheldygg and aminalaee authored Nov 4, 2024
1 parent ab2d48a commit 9b08745
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/api_reference/model_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- name_plural
- icon
- category
- category_icon
- column_labels
- can_create
- can_edit
Expand Down
2 changes: 2 additions & 0 deletions docs/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ The metadata for the model. The options are:
* `name_plural`: Display plural name for this model. Default value is class name + `s`.
* `icon`: Icon to be displayed for this model in the admin. Only FontAwesome and Tabler names are supported.
* `category`: Category name to display group of `ModelView` classes together in dropdown.
* `category_icon`: Category icon to display.

!!! example

Expand All @@ -86,6 +87,7 @@ The metadata for the model. The options are:
name_plural = "Users"
icon = "fa-solid fa-user"
category = "accounts"
category_icon = "fa-solid fa-user"
```

## List page
Expand Down
2 changes: 1 addition & 1 deletion sqladmin/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ async def test_page(self, request: Request):

def _build_menu(self, view: ModelView | BaseView) -> None:
if view.category:
menu = CategoryMenu(name=view.category)
menu = CategoryMenu(name=view.category, icon=view.category_icon)
menu.add_child(ViewMenu(view=view, name=view.name, icon=view.icon))
self._menu.add(menu)
else:
Expand Down
3 changes: 3 additions & 0 deletions sqladmin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ async def test_page(self, request: Request):
category: ClassVar[str] = ""
"""Category name to group views together."""

category_icon: ClassVar[str] = ""
"""Display icon for category in the sidebar."""


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

0 comments on commit 9b08745

Please sign in to comment.