Skip to main content

📊 Dashboard

The dashboard is the admin's start page. You compose it in Python from widgets: statistics, lists of content, recent activity and scheduled tasks.

Compose a dashboard​

Most widgets get their data from a get_data(request) method you write. Subclass the built-in widget and implement it:

# blog/dashboard.py
from content_studio.dashboard.content_list import ContentListWidget
from content_studio.dashboard.statistic import StatisticWidget

from .models import Article


class PublishedArticlesWidget(StatisticWidget):
def get_data(self, request):
return {
"title": "Published articles",
"value": Article.objects.filter(status="published").count(),
}


class LatestArticlesWidget(ContentListWidget):
def get_data(self, request):
articles = Article.objects.order_by("-published_at")[:5]
return {
"title": "Latest articles",
"content": [
{"model": "blog.article", "id": str(article.pk), "title": article.title}
for article in articles
],
}

Then give the site a Dashboard with the widgets, in the order they appear:

# mysite/studio.py
from content_studio.admin import ContentStudioSite
from content_studio.dashboard import Dashboard
from content_studio.dashboard.activity_log import ActivityLogWidget

from blog.dashboard import LatestArticlesWidget, PublishedArticlesWidget


class BlogStudioSite(ContentStudioSite):
dashboard = Dashboard(
widgets=[
PublishedArticlesWidget(),
LatestArticlesWidget(),
ActivityLogWidget(),
]
)


admin_site = BlogStudioSite()

Point the ADMIN_SITE setting at the site:

# mysite/settings.py
CONTENT_STUDIO = {
"ADMIN_SITE": "mysite.studio.admin_site",
}

get_data returns a dictionary with the widget's data, or a Django REST Framework serializer that validates it. A widget's col_span sets how many grid columns it spans.

Built-in widgets​

  • StatisticWidget: one number with a title. get_data returns value and, optionally, title, prefix, suffix, a trend (a percentage) and a trend_sentiment ("positive", "negative" or "default").
  • ContentListWidget: a list of links to content. get_data returns a title, an optional description and content: items with the model label, the object's id, a title and an optional description.
  • ActivityLogWidget: the five latest changes made in the admin. It needs no configuration and only shows changes to models the editor may view.
  • ScheduledTasksWidget: the status of scheduled tasks, from your task runner. get_data returns tasks: items with a title, last_run_at, next_run_at, duration and a status ("RUNNING", "SCHEDULED", "SUCCESS" or "FAILURE").
  • SpacingWidget(col_span): empty space, to align the grid.

Your own widgets subclass one of these: the admin can only show the built-in widget types. System check content_studio.W012 reports a widget that does not.

Widget identity​

Each widget gets an ID from its class and its name, so every worker of a deployment agrees on it. Two widgets of the same class need an explicit widget_id (a UUID) to tell them apart; manage.py check reports duplicates.