{"id":13780704,"url":"https://github.com/wildfish/django-dashboards","last_synced_at":"2025-05-11T14:33:45.396Z","repository":{"id":153033337,"uuid":"621683554","full_name":"wildfish/django-dashboards","owner":"wildfish","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-09T09:07:02.000Z","size":17012,"stargazers_count":67,"open_issues_count":5,"forks_count":9,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-05-09T23:47:30.430Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wildfish.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"docs/contributing.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-31T07:01:58.000Z","updated_at":"2025-03-20T02:06:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"28389d11-d99d-4cd6-a6ed-343ebe008b58","html_url":"https://github.com/wildfish/django-dashboards","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wildfish%2Fdjango-dashboards","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wildfish%2Fdjango-dashboards/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wildfish%2Fdjango-dashboards/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wildfish%2Fdjango-dashboards/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wildfish","download_url":"https://codeload.github.com/wildfish/django-dashboards/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253580159,"owners_count":21930892,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:01:18.927Z","updated_at":"2025-05-11T14:33:44.492Z","avatar_url":"https://github.com/wildfish.png","language":"Python","funding_links":[],"categories":["Third Party Packages 📦 \u003ca name = \"tools\"\u003e\u003c/a\u003e"],"sub_categories":["Components"],"readme":"=================\nDjango Dashboards\n=================\n\nTools to help you build data dashboards in Django.\n\nhttps://github.com/wildfish/django-dashboards\n\n.. image:: https://github.com/wildfish/django-dashboards/actions/workflows/build.yml/badge.svg\n    :target: https://github.com/wildfish/django-dashboards\n\n.. image:: https://codecov.io/gh/wildfish/django-dashboards/branch/main/graph/badge.svg\n  :target: https://codecov.io/gh/wildfish/django-dashboards\n\n.. image:: https://badge.fury.io/py/django-dashboards.svg\n    :target: https://pypi.python.org/pypi/django-dashboards/\n\n.. image:: https://img.shields.io/pypi/pyversions/django-dashboards.svg\n    :target: https://pypi.python.org/pypi/django-dashboards/\n\nFeatures\n========\n\n* Dashboard view generation with components including stats, tables, charts and more.\n* HTMX driven dashboards and templates for a modern MPA interface.\n\nSupports Django 3.2 to 4.2, on Python 3.9+.\n\nSee the `full documentation \u003chttps://wildfish-django-dashboards.readthedocs.io\u003e`_ for details\nof how django-dashboards works.\n\n.. inclusion-quickstart-do-not-remove\n\nQuickstart\n==========\n\nThis is a quickstart guide for creating a simple dashboard.\n\nProject Setup\n-------------\n\nWe recommend using a virtual environment such as `pyenv \u003chttps://github.com/pyenv/pyenv\u003e`_ to manage your\ndependencies and Python versions. From this point we assume you have a environment setup, activated \u0026 pip installed.\n\nCreate a new Django project::\n\n    # Create the project directory\n    mkdir demo\n    cd demo\n\n    # Install\n    pip install django-dashboards\n\n    # Set up a new project\n    django-admin startproject demo .\n    cd demo\n    django-admin startapp mydashboard\n    cd ..\n\n    # Sync the database\n    python manage.py migrate\n\nDashboards\n----------\nFirst you need to setup a dashboard definition.  Create a new file :code:`demo/mydashboard/dashboards.py`::\n\n    from dashboards.dashboard import Dashboard\n    from dashboards.component import Text, Chart\n    from dashboards.registry import registry\n\n    from demo.mydashboard.data import DashboardData\n\n\n    class FirstDashboard(Dashboard):\n        welcome = Text(value=\"Welcome to Django Dashboards!\")\n        animals = Chart(defer=DashboardData.fetch_animals)\n\n        class Meta:\n            name = \"First Dashboard\"\n\n\n    registry.register(FirstDashboard)\n\n\nRemember to register your dashboard class in order for it to work with the auto urls.\n\nData\n----\nData for the dashboard component can be inline (welcome) or come from a callable (animals).\nIn the example above the data for animals is returned from fetch_animals.  We set this up now.\nCreate a new file :code:`demo/mydashboard/data.py`::\n\n    import json\n\n\n    class DashboardData:\n        @staticmethod\n        def fetch_animals(**kwargs) -\u003e str:\n            data = {\"giraffes\": 20, \"orangutans\": 14, \"monkeys\": 23}\n\n            return json.dumps(dict(\n                data=[\n                    dict(\n                        x=list(data.keys()),\n                        y=list(data.values()),\n                        type=\"bar\",\n                    )\n                ]\n            ))\n\nThis returns a json object with values for x, y, and type.  This is interpreted by the component and rendered as a bar chart.\n\nConfig\n------\nIn order to get the auto urls to register we need to update :code:`demo/mydashboard/apps.py`::\n\n    from django.apps import AppConfig\n\n\n    class MydashboardConfig(AppConfig):\n        default_auto_field = 'django.db.models.BigAutoField'\n        name = 'demo.mydashboard'\n\n        def ready(self):\n            # for registry\n            import demo.mydashboard.dashboards  # type: ignore # noqa\n\n\nURLs\n----\nNext we need to wire up the dashboard urls.  In :code:`demo/urls.py`::\n\n    from django.contrib import admin\n    from django.urls import include, path\n\n    urlpatterns = [\n        path('admin/', admin.site.urls),\n        path('dashboards/', include('dashboards.urls')),\n    ]\n\nSettings\n--------\nFinally add :code:`dashboards` and your new app :code:`demo.mydashboard` to INSTALLED_APPS in :code:`demo/settings.py`::\n\n    INSTALLED_APPS = [\n        ...\n        \"dashboards\",\n        \"demo.mydashboard\",\n    ]\n\nAnd we're done.\n\nViewing the Dashboard\n---------------------\nStart the Django server from the command line.::\n\n    python manage.py runserver\n\nThe dashboard urls are automatically generated based on the app name and dashboard meta name.\nFor this demo the url will be :code:`http://127.0.0.1:8000/dashboards/mydashboard/firstdashboard/`\n\n.. image:: _images/quickstart_dashboard.png\n   :alt: Demo Dashboard\n\nExpanding your dashboard\n------------------------\n\n`FirstDashboard was very simplistic, so lets expand on that and use some more components`. We'll inherit\nfrom `FirstDashboard` to create::\n\n\n    from dashboards.dashboard import Dashboard\n    from dashboards.component import Text, Chart, Table\n    from dashboards.registry import registry\n\n    from demo.mydashboard.data import DashboardData, ContentTypeTableSerializer, ContentTypeChartSerializer\n\n\n    class FirstDashboard(Dashboard):\n        welcome = Text(value=\"Welcome to Django Dashboards!\")\n        animals = Chart(defer=DashboardData.fetch_animals)\n\n        class Meta:\n            name = \"First Dashboard\"\n\n\n    class SecondDashboard(FirstDashboard):\n        express_animals = Chart(defer=DashboardData.express_animals)\n        content_types = Table(value=ContentTypeTableSerializer)\n        content_types_chart = Chart(defer=ContentTypeChartSerializer, grid_css_classes=\"span-12\")\n\n        class Meta:\n            name = \"Second Dashboard\"\n\n\n    registry.register(FirstDashboard)\n    registry.register(SecondDashboard)\n\nand::\n\n    import json\n\n    import plotly.express as px\n    from django.contrib.contenttypes.models import ContentType\n\n    from dashboards.component.chart import ChartSerializer\n    from dashboards.component.table import TableSerializer\n\n\n    class DashboardData:\n        @staticmethod\n        def fetch_animals(**kwargs) -\u003e str:\n            data = {\"giraffes\": 20, \"orangutans\": 14, \"monkeys\": 23}\n\n            return json.dumps(dict(\n                data=[\n                    dict(\n                        x=list(data.keys()),\n                        y=list(data.values()),\n                        type=\"bar\",\n                    )\n                ]\n            ))\n\n        @staticmethod\n        def express_animals(**kwargs):\n            data = dict(\n                animal=[\"giraffes\", \"orangutans\", \"monkeys\"],\n                value=[20, 14, 23]\n            )\n\n            fig = px.pie(\n                data,\n                names='animal',\n                values='value',\n            )\n\n            return fig.to_json()\n\n\n    class ContentTypeTableSerializer(TableSerializer):\n        class Meta:\n            columns = {\n                \"app_label\": \"App\",\n                \"model\": \"Model\"\n            }\n            model = ContentType\n\n\n    class ContentTypeChartSerializer(ChartSerializer):\n        class Meta:\n            fields = [\"app_label\", \"model\"]\n            model = ContentType\n\n        def to_fig(self, df):\n            fig = px.scatter(\n                df,\n                x=\"app_label\",\n                y=\"model\",\n            )\n\n            return fig\n\n\nHere we've added a few more components:\n\n* ``express_animals`` - A deferred pie chart, that instead of direct json renders via `plotly express \u003chttps://plotly.com/python/plotly-express/\u003e`_ to_json(), which allows us to quick;y convert dicts and Pandas DataFrames into charts.\n* ``content_types`` - A table (which could also be deferred) via our ``TableSerializer``, which outputs data direct from a django model.\n* ``content_types_chart`` - A chart which is an example of a ``ChartSerializer``, again outputting data direct from a django model.\n\nWhich looks like:\n\n\n.. image:: _images/quickstart_dashboard.gif\n   :alt: Demo Dashboard\n\n\n\n.. inclusion-quickstart-end-do-not-remove\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwildfish%2Fdjango-dashboards","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwildfish%2Fdjango-dashboards","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwildfish%2Fdjango-dashboards/lists"}