Django Admin's missing DetailView
.
Allows easy creation of a DetailView
via DSL for an object in Django Admin.
Django Admin's is missing detail views (by design). It's strengths lie in administering specific objects via form modification.
But, a common need is to allow internal staff/admins to view specific objects and and their related objects. Historically the recommendation was to build a separate website/frontend for this.
With models Company
, ContactInfo
, SalesLeads
, Orders
, Internal staff want to quickly understand the status of a particular Company
so a simple View displaying these 4 objects is very beneficial.
Then I can drill down into a Order
and see all related Product
s, OrderStatusUpdate
s, SalesComments
.
Via DSL, it is fast to stand up DetailView
s for many objects.
Information dense, grid layout. Function over form.
- Add View button to
changelist
for Object. detail_table_for()
builds object's details table.table_for()
builds a list ofctx["layout"]
holds the grid structure.
- Bootstrap as Webpack
- webpack_loader
- Direct add github to
pyproject.toml
,[email protected]:jenfi-eng/djadmin-detail-view.git
. - Add to
INSTALLED_APPS
- Create a
DetailView
and add mixinAdminDetailMixin
- To the object's admin add
AdminChangeListViewDetail
and functionget_default_detail_view
- Return the newly created DetailView in
get_default_detail_view
.
See example_project/companies/admin.py
for reference.
from django.contrib import admin
from djadmin_detail_view.views import AdminChangeListViewDetail, AdminDetailMixin
from my_app.companies.models import Company
@admin.register(Company)
class CompanyAdmin(AdminChangeListViewDetail, admin.ModelAdmin):
def get_default_detail_view(self):
return CompanyDetailView
class CompanyDetailView(AdminDetailMixin, DetailView):
model = Company
def get_context_data(self, request, *args, **kwargs):
ctx = super().get_context_data(request, *args, **kwargs)
company_details = details_table_for(
panel_name="Company Details",
obj=self.object,
details=[
detail("id"),
detail("legal_name"),
detail("tax_id"),
detail("total_completed_order_amount", value=lambda x: x.total_order_value()),
]
)
orders_list = table_for(
panel_name="Orders",
obj_set=self.object.order_set.all(),
cols=[
col("id"),
col("legal_name"),
col("total_value"),
col("created"),
]
)
ctx["layout"] = [
{
"row": [
{"col": company_details},
{"col": None},
],
},
]
This project is not ready for wider consumption. It is currently built for Jenfi and its internal needs. Thus, it has specific requirements such as django-hosts
that may need to be abstracted away.
PRs are welcome to make it more generally accessible.
Add config to allow specs to be run inside VSCode.
// .vscode/settings.json
{
"python.testing.pytestArgs": [
""
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
}
{
"name": "Django Web",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/server.py",
"args": [],
"django": true,
"justMyCode": false
},
- Add specs.
- Versioning and release on pypi.
- Allow non-webpack based installs.
This project takes a lot of inspiration from Rail's ActiveAdmin and its DSL.