Documentation Index
Fetch the complete documentation index at: https://mintlify.com/rahul-baberwal/django-var-cms/llms.txt
Use this file to discover all available pages before exploring further.
custom_object_actions lets you attach one-click action buttons to both the list view (per-row) and the detail view of any registered model. Common use cases include approving records, sending transactional emails, toggling status flags, triggering webhooks, or generating reports — all without leaving the CMS interface.
Defining Actions
Setcustom_object_actions to a list of action dictionaries on your VarCMSModelAdmin subclass. Each dictionary describes a single button:
| Key | Required | Description |
|---|---|---|
name | ✅ | Unique string identifier used in the action URL |
label | ✅ | Button text displayed to the user |
action_fn | ✅ | Callable or string name of a method on the admin class |
class | ❌ | CSS button style — "btn-primary", "btn-green", "btn-blue", "btn-danger", "btn-ghost" |
icon | ❌ | Lucide icon name displayed beside the button label (e.g., "check-circle", "mail", "shuffle") |
The action_fn Callable
The function referenced by action_fn receives three arguments: self (the admin instance), request (the current HttpRequest), and obj (the model instance the button was clicked on).
- Return
None(or nothing) → the user is automatically redirected back toHTTP_REFERER, or to the model’s list page if no referrer is set. - Return an
HttpResponse(redirect, JSON, file download, etc.) → that response is sent directly to the browser, giving you full control over routing.
action_fn can be provided either as a string (the name of a method on the admin class) or as a direct callable. Using a string is recommended for class-based organisation, but passing a standalone function works equally well:URL Pattern
Each action is registered at a predictable URL. You can construct it manually or use thevar_cms_action_url template tag:
"approve" action on company 42 in a crm app resolves to:
Permissions
The action view requires edit permission (has_permission(request, "edit")) by default. A user who does not have edit access on the model will receive a 403 Forbidden response when attempting to trigger any action.
Example 1 — Approve Company
This example checks whether a company has uploaded all required documents before marking it as approved. It uses Django’s message framework to surface errors or confirmations back to the user.Example 2 — Send Welcome Email
This example manually triggers a welcome email to a newsletter subscriber via Django’ssend_mail. Exceptions during delivery are caught and surfaced as error messages instead of crashing the request.
Example 3 — Toggle Active Status (from the Demo App)
The demo app’sCategoryAdmin includes a "Toggle Active" action that flips the is_active boolean and saves the object in a single click:
Dashboard Card Buttons — card_buttons
While custom_object_actions places buttons on individual object rows, card_buttons places navigation buttons at the bottom of a model’s dashboard card. Each button is a dict with the following keys:
| Key | Description |
|---|---|
label | Button text |
action | Built-in action: "list" (go to list view) or "add" (go to add form) |
url | Any custom relative or absolute URL (used when action is not set) |
class | Optional CSS class: "btn-primary", "btn-ghost", "btn-danger", "btn-green", "btn-blue" |
Default buttons
Whencard_buttons is not set (or is an empty list), django-var-cms automatically generates two default buttons for the card, subject to the user’s permissions:
- “View List” (
btn-ghost) — shown if the user haslistpermission - “Add New” (
btn-primary) — shown if the user hasaddpermission
Custom buttons
Definecard_buttons to replace the defaults with your own set. When action is "list" or "add", django-var-cms resolves the correct CMS URL automatically:
url for buttons that point outside the CMS: