Category: django

Finding a Bloody Decent Django Reporting Tool

I have never liked creating reports and custom tables based on filters for end users. I don’t think any developer does.

It feels like a very generic task and can be achieved (more) easily and with greater agility with the use of SQL. The group_by does not really exist in django. It smartly hides that from the developer and rightly so. It also seems that django was never strong on reporting, and was more reporting on news events…

Unfortunately when a client now asks for totals, group bys and custom filtering…django-tables2 just does not cut it anymore. So as a lazy developer, let us find something that can help us from reinventing the wheel and writing so much damn code.

What do I need out of the reporting package?

  • Automatic filters – filters of related fields, dates and relevant validation should be created automatically and be customisable
  • Fields to show, group by and aggregations should be options when generating the table of report
  • Subtotals and totals should show based on the grouped by options selected
  • Formats of output should be automatic based on django settings and be able to be overriden

But a picture paints 1000 words so here are some screenshots of what I am trying to create:

The main report screen:

Available options that are update dependent fields and uncheck users not linked to specific projects or clients:


The Grouped by report with totals and sub totals:

Django Reporting Packages

These are some of the packages I found. There are some more and a bit more info at

Updated (2018-02-23)

Django Model Report

I thought django-model-report was the white knight but it does not support python3.

It has exactly what I am looking for in a report, check this screenshot (grouped by):

Unfortunately it does not support python 3, so I have to throw it out of the mix.

Django Report Builder

A good offering, works with python3 but lacks the ability to select from a dropdown when filtering. You need the exact id or name (there is no dropdown) or available options.


You can export to xls or csv but there are some issues when translating, displaying and aggregating django native model fields like DurationField

django-report-builder display fields issue


A decent offering but you need to know SQL well and for me the schema was not showing at all. So it was difficult to guess the table and column names.



Which package is the King of Django Table Display?

I’ve been building a web app.

For simplicity sake, I have been making use of normal bootstrap tables and Django’s ListView. It works well, with my tests but it creates tables that are plain that lack search and sorting. Although pagination works nicely. There comes a time when you need to get professional and add a bit more functionality to improve the user’s experience.

What Else is out there

It was suggested to me that JQuery Datatables works well and I think it does. There are some packages available for django tables and some that use datatables so I thought I would give them a try and see if they could make my life simpler than implementing jQuery Datatables directly.


Set up feels pretty easy. Column ordering is built in, bollean fields are converted into ticks and crosses automagically. It changes emails to mailto: links., relatedLink and Link columns.

So a lot less stuff you need to change.

Using them with a class based view is a bit crappy and they are very much python based (server side). Not Javascript.

I’ve run into a bit of trouble when adding filtering as a class-based view from django-filters.

It is my opinion to save you time in customising for extra rows for different users and custom formats and display of columns, you should be using django-tables2 on your project.

It works really well with bootstrap and semantic-ui, just make sure to set the options correctly.

Documentation is also really good.


Documentation and github readme lacks a quick start or getting started section. Adding the simple bootstrapping steps should be the base of every readme and helps people get up and runnings as quick as possible.

There is just way too much text and pontification on how the server side implementation is trumping client side implementation of datatables.

Show us the bloody code…

I even made a pull request to fix this issue and create a getting started guide for django-datatable-view.

I also mentioned the issue but alas the owner of the repo has no clue and that shows in the above comments regarding the shit documentation. You can see her response to what I deem a simplification and improvement to the project. Shot down in flames by this SJW.

I tried but now that repo is dead to me and to the python/django community. It is irrelevant and I recommend you avoid using django-datatable-view because it is crappy and unmaintained.

Well it seems there are issues as get_all_field_names is being used but it was removed in django >= 1.10


Looked promising but it seems to be unloved and was hurt by the changes in jQuery datatables 1.10 . The issue I got was not resolved and hence I could not move forward.

Not one to use this day and age.


Well just looking at the github page, it isn’t simple it requires special settings, MiddleWare and ContextProcessors

Read it all here


Hopefully I have left the best for last.

Nope, also having trouble with this thing.

What Now?

It is very important of you have an app with even 1 table that you use django-tables2 it will make your life that much easier in terms of creating and displaying tables.

I made use of the Datatables library on it’s own with django-tables2 as the packages that are supposed to do this neatly and effectively don’t really do that and are pretty much not at the level.

In my case I just disabled ordering and filtering (which is poor server-side style) and did not do server side pagination.

All of that is handled with datatables and it worked out pretty well. I also added a few settings to make it work with bootstrap:

class UserTable(tables.Table):
 '''User table
 class Meta:
 model = User
 template_name = 'django_tables2/bootstrap-responsive.html'
 attrs = {
 'class': 'table table-bordered table-striped table-hover',
 'id': 'userTable'
 fields = (
 'first_name', 'last_name', 'email',
 'company', 'role', 'employee_type',
 orderable = False
 empty_text = '-'

Then in the template displaying the table and initialising data tables is pretty easy with:

<div class="row">
<div class="col-xs-12">{% render_table table %}</div>


{% block page_js %}
<script type="text/javascript" src="{% static '/js/jquery.dataTables.min.js' %}"></script>
<script type="text/javascript" src="{% static '/js/dataTables.bootstrap.min.js' %}"></script>
{% endblock %}

Sending Notifications with Django and almost falling into a Trap

I almost fell into a trap…

I have been developing a new product that sends emails to certain manager users when certain events happen. I am manually handling these tasks with ye old send_email. I also wanted to  bring in a facebook/twitter style notifications so managers can see things that require their attention when logging in.

I couldn’t see the wood for the trees for a while there, I was looking at how to create bootstrap notifications on the nav bar. I had even written a test for it.

Avoiding the Trap

Then it occurred to me that an email notification and a notification bell on the nav bar is kind of the same thing and manually managing both events for the many events to be done on the site in the future is quite simply madness.

Go back to the fundamentals of python:

Don't reinvent the wheel and simple is better than complex

The Requirements

Let us just revisit what we want it to do, as simply as possible:

  1. Send emails to users when certain events happen
  2. Have notifications linked to specific users they can view when they are on the site
  3. Ability to mark some notifications as read

Notification Frameworks

So I scrapped the manually sending out notifications, although I had already created a few events that sent emails out. I am going to reuse a solution to a problem that surely has been solved already.

To start I searched google and github with terms like django notifications and I found a few potentials. One thing to note is that sometimes you don’t find your required simple solution easily and have to do a lot of testing first. You can see this from my django moderation article.

Here is a list of the frameworks I found:

  • django-notifications – GitHub notifications alike app for Django [595 stars]
  • pinax-notifications – user notification management for the Django web framework [573 stars]
  • django-nyt – Notification system for Django with batteries included: Email digests, user settings, JSON API [83 stars]
  • django-notify-x – Notification system for Django [122 stars]
  • django-webline-notifications – A python library, which allow you notify everything to user(s) simply

Django Notifications

After reading through the readme, Sending email to users has not been integrated into this library. So I will have to implement myself, other than that the way it works seems nice and simple.

There were a few issues when I installed it, like the docs were not in line with the pip installed version of the code. There are a few open issues and does not support python 3.6 and django 2.0.

It works okay but the templates are very basic and although the fundamentals behind it (including the models) are great: Actor -> Verb -> Action Object -> Target.

However you need to do quite a bit of heavily lifting by overriding templates and creating custom js callbacks to make it into a professional notification system. So I decided to try pinax-notifications instead

Pinax Notifications

Pinax is a fork of django-notifications there were quite a few issues on it at the time of writing however they do support python 3.6 and django 2

Their build was passing while django-notifications was failing.

Unfortunately after setting it up it lacks a few key features like the notification templates and stream of content that was available in django-notifications. It does send emails quite well but doesn’t have views for viewing all your notifications.

So it seems to be primarily focused on emails. The only view it provides is the notification/settings where you can set which notifications you want to receive.

It is not on the level and would require even more customisation that django-notifications-hq