Dashboards combine KPI cards, ECharts visualizations, and tables. Each app contributes generators through dashboard.py registered on DefaultDashboardGenerator.

This post is Part 11 of 28 in the Horilla CRM Technical Blog series.

What are Horilla CRM dashboards?

Horilla CRM dashboards enable you to:

  • Per-model chart_func and table_func hooks
  • Clickable chart segments deep-link to filtered lists
  • Company-scoped querysets
  • Funnel, bar, line, and custom ECharts types

Data models

horilla/contrib/dashboard/models.py:

ModelPurpose
DashboardFolderOrganize dashboards
DashboardLayout container per user/role
DashboardComponentKPI, chart, or table widget
ComponentCriteriaFilters driving widget data

All extend HorillaCoreModel — company-scoped.

App contributions via dashboard.py

Leads registers chart builders (Part 1):

# horilla_crm/leads/dashboard.py
def create_lead_source_charts(self, queryset, model_info):
    data = queryset.values("lead_source").annotate(count=Count("id"))
    return {
        "title": "Leads by Source",
        "type": "funnel",
        "data": {"labels": labels, "data": values, "urls": urls},
    }

DefaultDashboardGenerator discovers these functions when the dashboard filters to Lead records. Chart segments link back to filtered list views via URL query params.

Chart types

Common type values in dashboard config:

  • bar, line, pie, funnel, gauge

Frontend renders via ECharts JS loaded in the dashboard template — server sends JSON config only.

KPI components

Components can show:

  • Single aggregate (COUNT, SUM on MoneyField)
  • Comparison vs previous period
  • Drill-down into list view

Best practices

  1. Keep aggregations in dashboard.py — not in templates
  2. Use get_section_info_for_model() for consistent filter URLs
  3. Test with large querysets — add DB indexes on grouped fields

Next: Part 12 — Mail integration and templates.

Benefits of Dashboard in Horilla CRM

  • Apps own their metrics — no core hard-coding
  • Executives and reps see live pipeline data
  • Reuses the same Lead queryset as list views

Add dashboard.py to any module that needs analytics. Register chart builders, and they appear when users filter dashboards to your model.

Continue the series

More posts are at Horilla Blogs; share feedback on GitHub.

Share this article