{"id":15572902,"url":"https://github.com/dropseed/django-admincharts","last_synced_at":"2025-04-06T19:13:03.705Z","repository":{"id":39152005,"uuid":"382162937","full_name":"dropseed/django-admincharts","owner":"dropseed","description":"Add Chart.js visualizations to your Django admin using a mixin class","archived":false,"fork":false,"pushed_at":"2025-01-01T00:20:46.000Z","size":335,"stargazers_count":41,"open_issues_count":3,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T13:08:47.115Z","etag":null,"topics":["chartjs","django","django-admin"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/django-admincharts/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dropseed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2021-07-01T21:43:07.000Z","updated_at":"2025-03-29T06:06:44.000Z","dependencies_parsed_at":"2023-02-02T18:32:43.261Z","dependency_job_id":"e0ff836a-62dc-4cb3-9ed9-8e48abdd1f83","html_url":"https://github.com/dropseed/django-admincharts","commit_stats":{"total_commits":64,"total_committers":3,"mean_commits":"21.333333333333332","dds":0.484375,"last_synced_commit":"9a421192ca53d5c3035f28d821d3caf1e8467fca"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropseed%2Fdjango-admincharts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropseed%2Fdjango-admincharts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropseed%2Fdjango-admincharts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropseed%2Fdjango-admincharts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dropseed","download_url":"https://codeload.github.com/dropseed/django-admincharts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247535519,"owners_count":20954576,"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":["chartjs","django","django-admin"],"created_at":"2024-10-02T18:07:58.403Z","updated_at":"2025-04-06T19:13:03.688Z","avatar_url":"https://github.com/dropseed.png","language":"Python","readme":"# django-admincharts\n\nAdd [Chart.js](https://www.chartjs.org/docs/latest/) visualizations to your Django admin using a mixin class.\n\n## Example\n\n![django-admincharts example](https://user-images.githubusercontent.com/649496/124196798-c3ccee80-da92-11eb-9c2a-c0f94171d071.png)\n\n```python\nfrom django.contrib import admin\n\nfrom .models import BillingAccount\nfrom admincharts.admin import AdminChartMixin\nfrom admincharts.utils import months_between_dates\n\n\n@admin.register(BillingAccount)\nclass BillingAccountAdmin(AdminChartMixin, admin.ModelAdmin):\n    def get_list_chart_data(self, queryset):\n        if not queryset:\n            return {}\n\n        # Cannot reorder the queryset at this point\n        earliest = min([x.ctime for x in queryset])\n\n        labels = []\n        totals = []\n        for b in months_between_dates(earliest, timezone.now()):\n            labels.append(b.strftime(\"%b %Y\"))\n            totals.append(\n                len(\n                    [\n                        x\n                        for x in queryset\n                        if x.ctime.year == b.year and x.ctime.month == b.month\n                    ]\n                )\n            )\n\n        return {\n            \"labels\": labels,\n            \"datasets\": [\n                {\"label\": \"New accounts\", \"data\": totals, \"backgroundColor\": \"#79aec8\"},\n            ],\n        }\n```\n\n## Installation\n\nInstall from [pypi.org](https://pypi.org/project/django-admincharts/):\n\n```console\n$ pip install django-admincharts\n```\n\nAdd `admincharts` to your Django `INSTALLED_APPS`:\n\n```python\nINSTALLED_APPS = [\n    ...\n    \"admincharts\",\n]\n```\n\nUse the `AdminChartMixin` with an `admin.ModelAdmin` class to add a chart to the changelist view.\n\nOptions can be set directly on the class:\n\n```python\nfrom django.contrib import admin\nfrom admincharts.admin import AdminChartMixin\n\n@admin.register(MyModel)\nclass MyModelAdmin(AdminChartMixin, admin.ModelAdmin):\n    list_chart_type = \"bar\"\n    list_chart_data = {}\n    list_chart_options = {\"aspectRatio\": 6}\n    list_chart_config = None  # Override the combined settings\n```\n\nOr by using the class methods which gives you access to the queryset being used for the current view:\n\n```python\nclass MyModelAdmin(AdminChartMixin, admin.ModelAdmin):\n    def get_list_chart_queryset(self, changelist):\n        ...\n\n    def get_list_chart_type(self, queryset):\n        ...\n\n    def get_list_chart_data(self, queryset):\n        ...\n\n    def get_list_chart_options(self, queryset):\n        ...\n\n    def get_list_chart_config(self, queryset):\n        ...\n```\n\nThe `type`, `data`, and `options` are passed directly to Chart.js to render the chart.\n[Look at the Chart.js docs to see what kinds of settings can be used.](https://www.chartjs.org/docs/latest/configuration/)\n\nBy default, the objects in your chart will be the objects that are currently visible in your list view.\nThis means that admin controls like [search](https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields) and [list filter](https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter) will update your chart,\nand you can use the Django [pagination](https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_per_page) [settings](https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_max_show_all) to control how many objects you want in your chart at a time.\nTo ignore pagination but still respect search/filter,\nyou can override the `get_list_chart_queryset` method to return the full queryset:\n\n```python\nclass MyModelAdmin(AdminChartMixin, admin.ModelAdmin):\n    def get_list_chart_queryset(self, changelist):\n        return changelist.queryset\n```\n\nAnd if you want, you can also sidestep the list queryset entirely by using overriding `get_list_chart_queryset` with your own query:\n\n```python\nclass MyModelAdmin(AdminChartMixin, admin.ModelAdmin):\n    def get_list_chart_queryset(self, changelist):\n        return MyModel.objects.all()\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdropseed%2Fdjango-admincharts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdropseed%2Fdjango-admincharts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdropseed%2Fdjango-admincharts/lists"}