Skip to main content

No project description provided

Project description

Django Admin Detail View

Django Admin's missing DetailView.

Allows easy creation of a DetailView via DSL for an object in Django Admin.

Companies' changelist added View

Company's DetailView

Contact's DetailView

Why this exists

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.

Theory

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 Products, OrderStatusUpdates, SalesComments.

Via DSL, it is fast to stand up DetailViews for many objects.

Beliefs

Information dense, grid layout. Function over form.

Features

  • Add View button to changelist for Object.
  • detail_table_for() builds object's details table.
  • table_for() builds a list of
  • ctx["layout"] holds the grid structure.

Pre-reqs

  • Bootstrap as Webpack
  • webpack_loader

Install

  1. Direct add github to pyproject.toml, git@github.com:jenfi-eng/djadmin-detail-view.git.
  2. Add to INSTALLED_APPS
  3. Create a DetailView and add mixin AdminDetailMixin
  4. To the object's admin add AdminChangeListViewDetail and function get_default_detail_view
  5. Return the newly created DetailView in get_default_detail_view.

See example_project/companies/admin.py for reference.

Code Example

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},
                ],
            },
        ]

Current Open Source Status

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.

VSCode

Testing

Add config to allow specs to be run inside VSCode.

// .vscode/settings.json
{
  "python.testing.pytestArgs": [
    ""
  ],
  "python.testing.unittestEnabled": false,
  "python.testing.pytestEnabled": true,
}

Web Launch Config

{
    "name": "Django Web",
    "type": "python",
    "request": "launch",
    "program": "${workspaceFolder}/server.py",
    "args": [],
    "django": true,
    "justMyCode": false
},

TODO

  1. Add specs.
  2. Versioning and release on pypi.
  3. Allow non-webpack based installs.

Credit

This project takes a lot of inspiration from Rail's ActiveAdmin and its DSL.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djadmin_detail_view-0.2.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djadmin_detail_view-0.2.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file djadmin_detail_view-0.2.0.tar.gz.

File metadata

  • Download URL: djadmin_detail_view-0.2.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Darwin/24.3.0

File hashes

Hashes for djadmin_detail_view-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d93ede821e0da8a99d9ddf0568e6eb604c22b4144f6117a6b2410eca887e6ffd
MD5 d5e17354424e3935b8c98b9ea04e07b5
BLAKE2b-256 6e78584bbfd508d955a4a89e98bba01c1a9d2920eefa849409961020557234e8

See more details on using hashes here.

File details

Details for the file djadmin_detail_view-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for djadmin_detail_view-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aafeadfbf3d53960b30a9c8fef800fcde79227c2a20692dcfa7b1187edcf13c4
MD5 4d4acd75f8694549cb982ef4c7b76e7c
BLAKE2b-256 eb1ab8d1faf838cd71eb3b0bd992616ae81442c226e366c1cd290d72d954f381

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page