Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table group option in the table menu #278

Merged
merged 9 commits into from
Jan 26, 2023
Prev Previous commit
Next Next commit
add docs
  • Loading branch information
sinisaos committed Jan 25, 2023
commit bfcda7ce00a9593b218fc184b5693e621d581492
25 changes: 25 additions & 0 deletions docs/source/table_config/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,31 @@ information.

-------------------------------------------------------------------------------

menu_group
----------

We can set groups of tables in the table navigation sidebar. This is useful
when we have many tables and in this way we can organize the tables into
groups for better visibility:

.. code-block:: python

from piccolo_admin.endpoints import TableConfig

movie_config = TableConfig(
Movie,
menu_group="Movies"
)

director_config = TableConfig(
Director,
menu_group="Movies"
)

create_admin([director_config, movie_config])

-------------------------------------------------------------------------------

Source
------

Expand Down
8 changes: 4 additions & 4 deletions piccolo_admin/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,17 +872,17 @@ def get_meta(self) -> MetaResponseModel:

def get_table_list(self) -> JSONResponse:
dantownsend marked this conversation as resolved.
Show resolved Hide resolved
"""
Returns a list of all apps with tables registered with the admin.
Returns the list of table groups registered with the admin.
"""
app_names: t.Dict[t.Optional[str], t.List[str]] = {}
group_names: t.Dict[t.Optional[str], t.List[str]] = {}
table_config_data = {
i.table_class._meta.tablename: i.menu_group
for i in self.table_configs
}
for k, v in sorted(table_config_data.items()):
app_names.setdefault(v, []).append(k)
group_names.setdefault(v, []).append(k)

return JSONResponse(app_names)
return JSONResponse(group_names)

###########################################################################

Expand Down