Menu

How I Added Live Charts to the Django Admin Without Installing a Single Package
πŸ–ΌοΈ

How I Added Live Charts to the Django Admin Without Installing a Single Package

DEV Community: djangoΒ·Vicente G. ReyesΒ·5 months ago
#UsHevVj9
#dev#chart#admin#django#extra_context
Reading 0:00
15s threshold

The Django admin is a powerful tool that most developers underuse. Out of the box it gives you a filterable, searchable table for every model β€” but it stops short of anything visual. If you want to see trends over time, you're staring at rows.

I recently added a PageVisit model to my portfolio backend to track which blog posts, projects, and services people actually read. After 73 visits in two days I realised most of them were bots β€” but that problem aside, I also wanted a fast way to see visit trends without leaving the admin. Here's how I wired up three Chart.js charts with no new Python dependencies.

The Setup

The PageVisit model records one row per visit:

class PageVisit ( models . Model ): PAGE_TYPE_CHOICES = [ ( " blog_post " , " Blog Post " ), ( " project " , " Project " ), ( " service " , " Service " ), ] DEVICE_TYPE_CHOICES = [ ( " desktop " , " Desktop " ), ( " mobile " , " Mobile " ), ( " tablet " , " Tablet " ), ( " bot " , " Bot " ), ( " unknown " , " Unknown " ), ]

page_type = models .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.