diff --git a/README.rst b/README.rst index 4b228f4..1ff0dd5 100644 --- a/README.rst +++ b/README.rst @@ -80,6 +80,8 @@ Settings +------------------------------------+---------------+---------------------------------+----------------------------------------------------------------------------------------------------+ | ``DATA_BROWSER_APPS_EXPANDED`` | ``True`` | | Are the app sections of the homepage model list expanded by default. | +------------------------------------+---------------+---------------------------------+----------------------------------------------------------------------------------------------------+ +| ``DATA_BROWSER_ADMIN_SITE`` | ``None`` | `Admin Site`_ | Specify an ``admin.AdminSite`` to use (default is ``admin.site``). | ++------------------------------------+---------------+---------------------------------+----------------------------------------------------------------------------------------------------+ Permissions @@ -406,7 +408,37 @@ Then we need to tell the Data Browser we want ``p95`` on duration fields. lambda x: Percentile(0.95, x), DurationType ) +Admin Site +---------- + +You can create and use a custom ``admin.AdminSite`` (see https://docs.djangoproject.com/en/4.2/ref/contrib/admin/). + +To do so, in your ``settings.py``, add: + +.. code-block:: python + + from django.contrib import admin + + class BrowserAdminSite(admin.AdminSite): + pass + + DATA_BROWSER_ADMIN_SITE = BrowserAdminSite(name='data_browser') + +Then, in any ``admin.py``, register the models as usually but using ``DATA_BROWSER_ADMIN_SITE``. + +For instance in ``myapp/admin.py``: + +.. code-block:: python + + from django.contrib import admin + from django.conf import settings + from myapp.models import MyAdminModel, MyBrowsableModel + + # register in admin only + admin.register(MyAdminModel) + # register in data browser only + settings.DATA_BROWSER_ADMIN_SITE.register(MyBrowsableModel) Version numbers --------------- diff --git a/data_browser/common.py b/data_browser/common.py index b63eaa1..3bfb7c3 100644 --- a/data_browser/common.py +++ b/data_browser/common.py @@ -25,6 +25,7 @@ class Settings: "DATA_BROWSER_USING_DB": "default", "DATA_BROWSER_ADMIN_OPTIONS": {}, "DATA_BROWSER_APPS_EXPANDED": True, + "DATA_BROWSER_ADMIN_SITE": None, } def __getattr__(self, name): diff --git a/data_browser/orm_admin.py b/data_browser/orm_admin.py index 6360223..13448c6 100644 --- a/data_browser/orm_admin.py +++ b/data_browser/orm_admin.py @@ -191,7 +191,8 @@ def get_common(admin, model): hidden_model_fields[model].update(_get_option(admin, "hide_fields", request)) model_admins = {} - for model, model_admin in site._registry.items(): + admin_site = settings.DATA_BROWSER_ADMIN_SITE or site + for model, model_admin in admin_site._registry.items(): if visible(model_admin): model_admins[model] = model_admin all_model_fields[model].update(model_admin.get_list_display(request))