Package: django-adminstats
Django Admin Stats allows you to create and display charts of your data
using the django admin. It usesc3to display charts.A sample chart from the demo being visualizedFeaturesEasy-no configuration charting using the “explore” function.Supports generating statistics from django models and fromtrackstatsmetrics.Also allows for custom statistics generation by making your ownRegistrationsubclass.Nice JavaScript charts with c3, falls back to a plain table without
JavaScript.Add filters & group data by setting query parameters on the criteriaLimitationsOne dimension/axis of the chart is always the date. There’s no way to
specify a chart that isn’t “by date”.InstallationInstallation is straightforward. Installdjango-adminstatswith pip, and
then add the followingINSTALLED_APPSin your config. If you already have
something that replacesdjango.contrib.admin, you’ll need to manually
add links to the “Explore” pages if you want to use the Explore tool.INSTALLED_APPS=[...'django_adminstats.apps.AdminConfig',# replaces django.contrib.admin'django_adminstats',...]Using the Explore ToolThe Explore tool lets any user with access to the admin site view charts
for whatever models they have access to. Unlike the following Charts system,
these charts are generated on-the-fly, and don’t require any setup.The explore tool is closely integrated into the functionality that already
exists in the django admin. The consequence of this is that if you want to
do any grouping or filtering you have to definefilterson your admin
pages usingModelAdmin.list_filter.One of the benefits of the Explore tool is that once you’ve applied filters,
you can click on the “View Entries” button, to view the selected entries in
the regular admin page.Using ChartsUsing charts allows you to generate charts with a high degree of flexibility,
including things like averages, sums, substring queries, etcetera. Most
of the the regular django querying abilities are available in charts, even
if the fields aren’t normally visible in the admin.This is nice in that it is flexible, but it requires a bit of setup and its
not a good idea to give create/edit access to non-superusers due to the ability
to query data on almost any field.Registering StatisticsIn order to do anything, you’ll need register some models or trackstats
metrics. You can find examples of this intests/models.py, but the short
of it looks like this:fromdjango_adminstats.registryimportregister_modelclassCurrency(models.Model):slug=models.CharField(max_length=10)name=models.CharField(max_length=100)current_usd_rate=models.DecimalField()sign=models.CharField(max_length=10,default='$')classTransaction(models.Model):amount=models.DecimalField()currency=models.Foreignkey(to=Currency)date=models.DateTimeField(auto_now_add=True)register_model(Transaction)By default, we look for a field called ‘date’ on the model, and it should be
either aDateFieldorDateTimeField. If you want to use a different,
field (for example if you’re using Django’s default user and you want to chart
by ‘joined_at’) you need to create a registration subclass.fromdjango_adminstats.registryimportregistry,registerclassUserRegistration(ModelRegistration):date_field='joined_at'register(UserRegistration())Creating ChartsYou can add charts in the admin. In order for the chart to show anything, you
need to add criteria. By default, it will just show a count of all the items
charted by the date field, if you to change this, you need to add things in
the filter query, axis query, and group query fields.First, the content of these fields is formatted like a URL querystring,
for example a filter query ofmessage=Hello%20World&x=yis equivalent to.filter(message='HelloWorld',x='y'). Note that you only use thekey0=value0&key1=value1form in the filter query, the axis and group
queries are justkey0&key2.Second, you can use lookups and relations just like in a normal django
query (e.g.field__gt=2orfield__related_field).Finally, you can also specify functions to use on the field by doingfield:function. For exampleid:countis the default axis query when
the field is left blank.DemoJust runmake demoand log in with useradminand passwordadmin.CHANGES0.7.4Use the view instead of change permission for viewing charts0.7.3Fix error in description generation0.7.2Make chart control list items more visually distinct0.7.1Fix packaging problem (missing files)0.7.0Add new “Explore” charts, upgrading users may want to adjustINSTALLED_APPS.0.6.3Drop pbr for regular setuptools, add VERSION attributeFix some new problems that flake was catchingAdd screenshot of chart0.6.2Fix problem where criteria with same stats would clobber each other0.6.1fix programming bug with by-month trackstats metrics, better test coverage0.6fix autocomplete options for tracstats criteriaFix problems with the autocomplete not (re)initializing properly0.5Add autocomplete for query fields in admin, and rename query fields0.4Add documentation for query fields and registrationsAdd copy chart admin action0.3Add the ability to filter/group related models in trackstats by-object
stats registrations