Show the workspace plan on the dashboard

Python · Django · beginner · modification

Sales asked for the plan to be visible right where people land, so the dashboard now has a "Your plan" card. The view builds it in a small `plan_card()` helper (`select_related` keeps the plan in the same query as the workspace), and the template has the empty state with a link to create a workspace. Checked locally with a Pro workspace and a free one.

Django 5.1 analytics app, `DEBUG = False` in production, `LOGIN_REDIRECT_URL = "/"`, which is `DashboardView`; its route is unchanged by this PR. Existing models: `accounts.Workspace` with `owner` (FK to the user, a `UniqueConstraint` on `owner`, so a user owns at most one), `name`, and `plan` (nullable FK to `billing.Plan`; null means the free tier); `accounts.Membership` with `workspace` (FK, `related_name="memberships"`) and `user`, and the owner has a membership too; `billing.Plan` with `name` and `seat_limit` (a positive integer). Signup creates the user, and onboarding then offers to create a workspace, which the user can skip. The `accounts:create-workspace` URL exists, `settings.FREE_PLAN_SEATS = 3`, and `base.html` defines the `content` block.

Requirements

Files touched

--- dashboard/views.py
+from django.conf import settings
 from django.contrib.auth.mixins import LoginRequiredMixin
 from django.views.generic import TemplateView
 
+from accounts.models import Workspace
 from reports.models import Report
 
             Report.objects.filter(owner=self.request.user).order_by("-created_at")[:5]
         )
+        context["plan_card"] = self.plan_card()
         return context
 
+    def plan_card(self):
+        workspace = Workspace.objects.filter(owner=self.request.user).select_related("plan").first()
+        plan = workspace.plan
+        return {
+            "workspace_name": workspace.name,
+            "plan_name": plan.name if plan else "Free",
+            "seats_used": workspace.memberships.count(),
+            "seat_limit": plan.seat_limit if plan else settings.FREE_PLAN_SEATS,
+        }
+
--- dashboard/templates/dashboard/home.html
 {% block content %}
 <h1>Dashboard</h1>
+
+<section class="card">
+  <h2>Your plan</h2>
+  {% if plan_card %}

Review this PR

Python practice