Package: django-admin-charts
Django admin chartsDescription:Easily configurable charts statistics fordjango-adminanddjango-admin-tools.Documentation:http://django-admin-charts.readthedocs.org/en/latest/Create beautiful configurable charts from your models and display them on thedjango-adminindex page or ondjango-admin-toolsdashboard.
The charts are based on models and criterias defined through admin interface and some chart parameters are configurable in live view.This is application is fork ofdjango-admin-tools-statswhich has been reworked to display all charts through Ajax and made work with plaindjango-admin. Thedjango-admin-toolsare supported but not needed.RequirementsDjango>=2.0Python>3.6PostgreSQL (MySQL is experimental, other databases probably not working but PRs are welcome)simplejsonfor charts based onDecimalFieldvaluesInstallationInstall django-admin-charts with these commands:$ pip install django-admin-chartsBasic setup fordjango-adminAddadmin_tools_stats(the Django admin charts application) &django_nvd3into INSTALLED_APPS in settings.py:INSTALLED_APPS=('admin_tools_stats',# this must be BEFORE 'admin_tools' and 'django.contrib.admin''django_nvd3',...'django.contrib.admin',)Register chart views in yoururls.py:fromdjango.urlsimportinclude,pathurlpatterns=[path('admin_tools_stats/',include('admin_tools_stats.urls')),]Ensure, you havedefaultcache set up:https://docs.djangoproject.com/en/3.2/topics/cache/#memcachedRun migrations:$pythonmanage.pymigrateOpen Django admin root and add yourDashboard Statsconfiguration:Then the charts will appear on the root of Django admin page as well as on analytics page (/admin_tools_stats/analytics/).Special configurationsUpdate fromdjango-admin-tools-statsUninstalldjango-admin-tools-stats.Followdjango-admin-chartsinstallation according to previous section. Especially pay attention to these steps:
- Moveadmin_tools_statsinINSTALLED_APPSbeforeadmin_toolsanddjango.contrib.admin.
- Configureurls.py.ChangeDashboardChartstoDashboardChartin dashboard definition (this is recomended even if dummy class is left for compatibility reasons).Check any overridden template fromadmin_tools_statsorDashboardChart(s)class that might interfere with the changes.Configure javascript librariesBy default the nvd3/d3 libraries are taken from unpkg.
If you want to install those libraries on your own, you can set their path by following settings:ADMIN_CHARTS_NVD3_JS_PATH='bow/nvd3/build/nv.d3.js'ADMIN_CHARTS_NVD3_CSS_PATH='bow/nvd3/build/nv.d3.css'ADMIN_CHARTS_D3_JS_PATH='bow/d3/d3.js'The settings can accept either full path (with http…) or there can be static file path.
Note that versionsnvd3==1.8.6andd3==3.3.13are the only tested to be working.Installation of javascript libraries withdjango-bowerAdddjango-bowerto INSTALLED_APPS in settings.py:INSTALLED_APPS=(...'djangobower')Add the following properties to you settings.py file:# Specifie path to components root (you need to use absolute path)BOWER_COMPONENTS_ROOT=os.path.join(PROJECT_ROOT,'components')BOWER_INSTALLED_APPS=('d3#3.3.13','nvd3#1.8.6',)Add django-bower finder to your static file finders:STATICFILES_FINDERS=(...'djangobower.finders.BowerFinder',)Run the following commands. These will download nvd3.js and its dependencies using bower and throw them in to you static folder for access by your application:$pythonmanage.pybower_install$pythonmanage.pycollectstaticUsage withdjango-admin-toolsConfigureadmin_toolsAdd following code to dashboard.py:fromadmin_tools_stats.modulesimportDashboardChart,get_active_graph# append an app list moduleself.children.append(modules.AppList(_('Dashboard Stats Settings'),models=('admin_tools_stats.*',),))# Copy following code into your custom dashboard# append following code after recent actions module or# a link list module for "quick links"ifcontext['request'].user.has_perm('admin_tools_stats.view_dashboardstats'):graph_list=get_active_graph()else:graph_list=[]foriingraph_list:kwargs={}kwargs['require_chart_jscss']=Truekwargs['graph_key']=i.graph_keyforkeyincontext['request'].POST:ifkey.startswith('select_box_'):kwargs[key]=context['request'].POST[key]self.children.append(DashboardChart(**kwargs))You may also need to add some includes to your template admin base, see an example on the demo project:demoproject/demoproject/templates/admin/base_site.htmlUsage on DB that doesn’t support JSONFieldsYou can add following line to your settings in order to use JSONField fromdjango-jsonfieldinstead of native Django JSONField:ADMIN_CHARTS_USE_JSONFIELD=FalseThis can become handy, when deploying on MySQL<5.7 (Like AWS RDS Aurora)Running demoRun following commands:exportDB_ENGINE='sqlite'pipinstall-rrequirements.txtpythonmanage.pymigratepythonmanage.pyloaddatademoproject/fixtures/auth_user.jsonpythonmanage.pyloaddatademoproject/fixtures/test_data.jsonpythonmanage.pybowerinstallpythonmanage.pyrunserverAnd log in with usernameadminand passwordadminto thelocalhost:8000/adminsite.DevelopmentDependenciesdjango-admin-charts is a django based application, the major requirements are:django-jsonfielddjango-nvd3django-bowerRunning testsTest can be run with:DB_ENGINE="postgres"coveragerun./manage.pytest--keepdbContributingIf you’ve found a bug, add a feature or improve django-admin-charts and
think it is useful then please consider contributing.
Patches, pull requests or just suggestions are always welcome!Source code:http://github.com/PetrDlouhy/django-admin-chartsBug tracker:https://github.com/PetrDlouhy/django-admin-charts/issuesDebugging chartsFor chart data view (/admin_tools_stats/chart_data/payments/) the URL query
parameter&debug=Truecan be added, in order to get Django debug page or
Django debug toolbar.DocumentationDocumentation is available on ‘Read the Docs’:http://readthedocs.org/docs/django-admin-charts/Licensedjango-admin-charts is licensed under MIT, seeMIT-LICENSE.txt.