Configuration
Property Paths
Properties are referenced by field name. Use __ to traverse relationships:
"properties": [
"title", # simple field
"author__name", # FK traversal
"author__country__code", # multi-hop FK
"tags", # M2M (renders all related objects)
"get_absolute_url", # method or property
]
The x() Helper
For more control over individual properties, use the x() shorthand to build a PropertyConfig:
from django_object_detail import x
"properties": [
"title",
x("author__name", title="Writer"),
x("published_date", detail="When the book was first published"),
x("rating", type="integer"),
x("notes", template="myapp/custom_notes.html"),
]
| Parameter | Description |
|---|---|
path |
Field name or __-separated path (required) |
title |
Override the auto-derived label |
detail |
Help text shown below the value |
type |
Override the auto-detected type (e.g. "date", "boolean") |
template |
Path to a custom template for rendering the value |
link |
LinkConfig or URL name string (see Links) |
badge |
BadgeConfig or color string (see Badges) |
Groups
Each entry in property_display is a group with a title and a list of properties:
property_display = [
{
"title": "Basic Info",
"description": "Core book metadata",
"icon": "bi bi-book",
"properties": [
"title",
"author__name",
x("isbn", detail="International Standard Book Number"),
],
},
]
| Parameter | Description |
|---|---|
title |
Group heading (required) |
description |
Subtitle or help text |
icon |
CSS class for an icon (e.g. Bootstrap Icons) |
properties |
List of strings, dicts, or PropertyConfig objects |
Properties can be mixed freely — plain strings, dicts with PropertyConfig fields, or x() / PropertyConfig instances.
View-Callable Fallback
If a path cannot be resolved on the model instance (the first segment is not an attribute or method on the instance), the resolver will try to call view.<path>(instance) instead.
This lets you compute display values using view-level context (e.g. self.request, view kwargs, or logic that doesn't belong on the model):
class BookDetailView(ObjectDetailMixin, DetailView):
model = Book
property_display = [
{
"title": "View-Computed",
"properties": [
x("view_computed_summary", title="Summary"),
],
},
]
def view_computed_summary(self, instance):
return f"{instance.title} by {instance.author_list()} ({instance.pages} pages)"
Rules:
- The view method must be callable — non-callable attributes on the view are ignored (value becomes
None) - If the path is found on the model (even as
None), the view fallback never runs — model always takes priority - This works automatically when using
ObjectDetailMixin, or when using the{% render_object_detail %}template tag from within a Django CBV template (Django addsviewto context viaContextMixin)