Skip to main content

Django Sastry (django-sastry)

CI License: MIT Python Versions Django Versions

A lightweight, zero-configuration dynamic CRUD administration interface and interactive visual Entity Relations (ER) Diagram engine for Django.

Django Sastry Interactive ER Diagram


Highlights & Features

  1. Interactive Visual Entity Relations (ER) Diagram:

    • Right-Anchored Selected Model: The active selected table is anchored to the extreme right, directly adjacent to the field inspector panel, with incoming reverse relations (has_many / child tables in cyan) and outgoing foreign key targets (in warm tones) plotted across vertical columns to the left.
    • Reactive Schema Navigation: Click any table card or foreign key to immediately make it the active model and move it to the right, refreshing all its upstream and downstream relations.
    • Multi-Column Bin-Packing: Automatically distributes child and referenced tables across vertical columns to the left to prevent tall single-column spillover for heavily connected models.
    • Vector Connection Canvas: Color-coded relational links with directional arrowheads for child table reverse relations and circular anchor nodes for foreign key targets.
    • Field-Level Inspector: Click any field in the active table to view its verbose name, Django internal type, nullability, blankness, uniqueness, database indexes, and reverse references.
  2. Zero-Config Dynamic CRUD:

    • Instant spreadsheet-style data grid for all registered Django models without requiring boilerplate admin.py registrations.
    • Paginated browsing, multi-field filtering, search, and inline record creation/editing.
    • Safe foreign key resolution with query limits preventing unbounded database loads.
  3. Modular ERP Application Foundation:

    • Extensible base template hierarchy (saz3.html -> saz3Nav.html -> s_home.html) powering enterprise suites (such as erp.saas3.in).
    • Easily inject custom modules into the navigation bar (Orders, Customer, Inventory, BOM, Sales, Billing).
    • Reusable getData / mdlData backend pipelines and subclassable frontend controllers (class CustomerController extends db_crud) with custom action triggers (like #ShowExtraDetail for Orders).
  4. Lightweight & Non-Intrusive:

    • Introspects model structure using Django's native Model._meta APIs in memory with zero database queries during diagram generation.
    • Zero external frontend dependencies: built with modern vanilla ES6 JavaScript and HTML5 Canvas.

The Core Philosophy: The 90/10 Architecture of Database Applications

"Most database applications center around selecting some filtered rows, and selecting one of them to view details in a custom way."

In traditional enterprise software development, building any new module (such as Customer Management, Job Cards, or Fabric Inventory) requires writing substantial boilerplate: API endpoints, pagination, multi-column search, filter drawers, sorting SQL, table HTML, form builders, and relational bindings. This mundane plumbing consumes 80% to 90% of development time.

django-sastry solves this by inverting the pyramid:

  • The 90% (Out-of-the-Box): Sastry automatically provides the high-performance relational data grid, instant dynamic search, multi-field filtering, pagination, inline modal editing, and visual ER schema diagram.
  • The 10% (Your Custom View): You only write the domain-specific detail view (an itemized order dossier, a bespoke canvas designer, or a retail invoice).

The Pattern in Action: A Complete Application in ~40 Lines

1. Backend: Thin View with getData (views.py)

@login_required
def CustomersList(request, ctyp=0):
    dat = json.loads(request.GET.get("dat", "{}"))
    types = CustomerType.objects.all().order_by("name").values_list("id", "name")
    if not ctyp and types:
        ctyp = types[0][0]
    if "filter" not in dat:
        dat["filter"] = {"customer_type_id": ctyp}
    dat["show"] = ["id", "customer_id", "name", "city", "state_id"]
    
    # Sastry handles the complete query, pagination, sorting, and serialization:
    data = getData("customer", "Customer", dat)
    data["ctype"] = types
    return render(request, "CustomerPage.html", data)

2. Frontend: Subclassing db_crud (customer.ts)

import { db_crud } from '/static/sastry/js/s_crud.js';

class CustomerListController extends db_crud<Customer> {
    constructor() {
        super();
        this.setData();
        // Hook custom filter buttons (e.g. Retail, Wholesale, Distributor)
        document.querySelectorAll('#FilterType a').forEach(el => {
            el.onclick = (e) => this.filterByType(e);
        });
        // Enable Sastry's built-in toolbar action button for drill-down
        const extraBtn = document.getElementById("ShowExtraDetail");
        extraBtn.textContent = "Orders";
        extraBtn.classList.remove('d-none');
    }

    ShowTab(tab: string) {
        super.ShowTab(tab);
        if (tab !== 'ExtraDetail') return;

        // Retrieve selected row from Sastry's active table
        const indexRow = document.querySelector('#index tbody tr.table-active') as HTMLTableRowElement;
        const customer = this.collection[indexRow.rowIndex - 1];

        // Fetch and display the custom detail view for this customer:
        fetch(`/customer/cust_order/${customer.id}/`)
            .then(res => res.text())
            .then(html => {
                document.getElementById('ExtraDetail')!.innerHTML = html;
                document.querySelector("#ExtraDetail #Bak2index")!.onclick = () => this.ShowTab('index');
            });
    }
}

By simply writing the custom detail view and connecting it via Sastry's extension points, you achieve a production-ready, enterprise-grade application in a few hours.


Documentation & User Manual

For an in-depth walkthrough of the system, including visual diagrams, color specifications, and step-by-step guides for extending Sastry into a custom ERP application, see the official manual:

👉 Comprehensive User Manual & ERP Extensibility Guide (docs/USER_MANUAL.md)

Manual Highlights:

  • Interactive Visual ER Diagram Guide: Details on the right-anchored model layout, right-to-left multi-column bin packing, color conventions (Gold, Cyan, Amber), and reactive table-clicking.
  • Dynamic CRUD Data Grid Guide: Filtering, sorting, pagination, inline edits, and foreign key optimization.
  • ERP Extensibility Guide: How to hook custom pages from the index navbar (s_home.html), author custom views reusing getData, build offcanvas filter drawers (FilterType), and subclass db_crud to display custom buttons like [⤢ Orders].
  • Python & JavaScript API Reference: Complete function signatures and class definitions.

Installation

Install via pip:

pip install django-sastry

Or install directly from GitHub:

pip install git+https://github.com/globalkrishna/django-sastry.git

Quickstart

1. Add to INSTALLED_APPS

In your Django settings.py:

INSTALLED_APPS = [
    # ...
    "sastry",
]

2. Configure Jinja2 Templates

In your Django settings.py:

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.jinja2.Jinja2",
        "APP_DIRS": True,
        "OPTIONS": {
            "environment": "config.jinja2.environment",
        },
    },
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "APP_DIRS": True,
        # ...
    },
]

Define the standard environment helper in config/jinja2.py:

from jinja2 import Environment
from django.templatetags.static import static
from django.urls import reverse

def environment(**options):
    env = Environment(**options)
    env.globals.update({"static": static, "url": reverse})
    return env

3. Include URLs

In your project's root urls.py:

from django.urls import path, include

urlpatterns = [
    # ...
    path("sastry/", include("sastry.urls")),
]

4. Collect Static Assets

python manage.py collectstatic --noinput

5. Access the Interfaces

Start your development server:

python manage.py runserver
  • Visual ER Diagram: Navigate to http://127.0.0.1:8000/sastry/er/
  • Dynamic CRUD Grid: Navigate to http://127.0.0.1:8000/sastry/

Security & Permissions

Access to /sastry/ and /sastry/er/ requires standard administrator authentication:

  • request.user.is_superuser or request.user.is_admin must evaluate to True.
  • Non-administrators receive an HTTP 403 Forbidden response.

License

MIT License. Developed by Krishnamurthy (Global Multimedia). Contributions and feature suggestions are welcome!

Metadata

Release files for django-sastry 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-sastry 1.0.7
File Size Uploaded Provenance Actions
django_sastry-1.0.7.tar.gz 53.7 kB Without provenance Details for django_sastry-1.0.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-sastry 1.0.7
File Interpreter ABI Platform Actions
django_sastry-1.0.7-py3-none-any.whl Python 3 none any Details for django_sastry-1.0.7-py3-none-any.whl

Total release size: 114.1 kB

Release files / django_sastry-1.0.7.tar.gz

Download URL django_sastry-1.0.7.tar.gz
Size 53.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cdf01aff154e5006d5bcb069661ba2033114aaa18275e3d8af8787053f66ac08
BLAKE2b-256 checksum
How to use checksums
9c99d3809eed310c2cd1a5ef9bd2c2725078bf455b48b07c8a1b37b17a1e8750
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / django_sastry-1.0.7-py3-none-any.whl

Download URL django_sastry-1.0.7-py3-none-any.whl
Size 60.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a1b87ca421a7ec12df515dd277d53990c477085b31028d12d7814f7c7dc2009
BLAKE2b-256 checksum
How to use checksums
330a3ce97238d2e8122fb75b070433ea8071ec8c62ba1f55c437dad699bf55cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for django-sastry 1.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page