Django Sastry (django-sastry)
A lightweight, zero-configuration dynamic CRUD administration interface and interactive visual Entity Relations (ER) Diagram engine for Django.
Highlights & Features
-
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.
- 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 (
-
Zero-Config Dynamic CRUD:
- Instant spreadsheet-style data grid for all registered Django models without requiring boilerplate
admin.pyregistrations. - Paginated browsing, multi-field filtering, search, and inline record creation/editing.
- Safe foreign key resolution with query limits preventing unbounded database loads.
- Instant spreadsheet-style data grid for all registered Django models without requiring boilerplate
-
Modular ERP Application Foundation:
- Extensible base template hierarchy (
saz3.html->saz3Nav.html->s_home.html) powering enterprise suites (such aserp.saas3.in). - Easily inject custom modules into the navigation bar (Orders, Customer, Inventory, BOM, Sales, Billing).
- Reusable
getData/mdlDatabackend pipelines and subclassable frontend controllers (class CustomerController extends db_crud) with custom action triggers (like#ShowExtraDetailfor Orders).
- Extensible base template hierarchy (
-
Native Multi-Tenant SaaS Architecture & Row-Level Isolation:
- Zero-boilerplate multi-tenancy: automatic row-level query scoping (
store_id = request.store.idortenant_id = request.tenant.id). - Role-based model whitelisting preventing non-superusers from inspecting or altering sensitive system tables.
- Automatic tenant foreign key stamping on record creation and safe tenant ownership validation on mutation.
- 100% backward-compatible: transparently disabled when
SASTRY_MULTI_TENANTis omitted.
- Zero-boilerplate multi-tenancy: automatic row-level query scoping (
-
Lightweight & Non-Intrusive:
- Introspects model structure using Django's native
Model._metaAPIs in memory with zero database queries during diagram generation. - Zero external frontend dependencies: built with modern vanilla ES6 JavaScript and pure SVG / HTML5 Canvas.
- Introspects model structure using Django's native
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 reusinggetData, build offcanvas filter drawers (FilterType), and subclassdb_crudto 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. (Optional) Enable Native Multi-Tenancy for SaaS
To enable automatic tenant/store row-level isolation and role-based model whitelisting, add SASTRY_MULTI_TENANT to your settings.py:
SASTRY_MULTI_TENANT = {
"ENABLED": True,
# Attributes on request to resolve active tenant (e.g. request.store or request.tenant)
"TENANT_REQUEST_ATTRS": ["store", "tenant", "organization", "company"],
# Model foreign key field names indicating tenant ownership
"TENANT_MODEL_FIELDS": ["store", "tenant", "organization", "company"],
# Permission mode: 'staff_with_tenant', 'superuser_only', or custom callable
"PERMISSION_MODE": "staff_with_tenant",
# Model Whitelist for tenant users (Superusers retain unrestricted access)
"ALLOWED_MODELS": {
"inventory": ["PurchaseOrder", "Vendor", "Purchase", "DebitNote", "StoreInventory"],
"billing": ["Customer", "SalesPerson", "Invoice"],
"catalog": ["Product", "ProductVariant"],
},
# Models always hidden from non-superusers
"EXCLUDED_MODELS": [
"admin.*", "sessions.*", "contenttypes.*", "auth.Permission",
"tenants.Tenant", "tenants.Store",
],
# Automatically stamp tenant foreign key when new records are created
"AUTO_STAMP_ON_CREATE": True,
}
5. Collect Static Assets
python manage.py collectstatic --noinput
6. 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/
Native Multi-Tenant SaaS Architecture
In multi-tenant SaaS environments (retail POS, franchise ERPs, multi-entity accounting), exposing monolithic admin interfaces to store staff is a critical security and privacy hazard.
django-sastry 2.0 incorporates a first-class Multi-Tenant Engine (sastry.tenant.TenantManager):
- Automatic Row-Level Scoping: Queries automatically inject tenant filters (
store_id = request.store.id). Store 160 can never view or manipulate rows from Store 161. - Model Gatekeeping: Tenant staff only see allowed business models (
ALLOWED_MODELS). Accessing system tables (Tenant,User,Sessions) returns an HTTP 403 Forbidden. - Safe Auto-Stamping: Newly created records are automatically stamped with
instance.store = request.store, eliminating cashier dropdown errors. - Cross-Tenant Mutation Protection: Updates and deletes verify tenant ownership before committing, preventing cross-tenant ID spoofing.
- Foreign Key Choice Scoping: Form dropdowns in modals only list relational choices (Vendors, Customers, Warehouses) belonging to the active tenant.
- 100% Backward Compatible: When
SASTRY_MULTI_TENANTis omitted, Sastry operates in standard single-tenant mode with zero overhead.
Security & Permissions
Access to /sastry/ and /sastry/er/ is evaluated dynamically based on your configuration:
- Single-Tenant Mode (Default): Access is strictly restricted to
request.user.is_superuserorrequest.user.is_admin. - Multi-Tenant Mode: Authenticated tenant staff operating within an active tenant context (
request.store/request.tenant) are granted scoped access to whitelisted models, while superusers retain global visibility across all stores.
License
MIT License. Developed by Krishnamurthy (Global Multimedia). Contributions and feature suggestions are welcome!
Metadata
Release files for django-sastry 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_sastry-2.0.1.tar.gz | 176.3 kB | Without provenance | Details for django_sastry-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_sastry-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for django_sastry-2.0.1-py3-none-any.whl |
Total release size: 242.1 kB
Release files / django_sastry-2.0.1.tar.gz
| Download URL | django_sastry-2.0.1.tar.gz |
|---|---|
| Size | 176.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b3692fe51af51778b7dde1e8059ff4cdf7e55ea8d80c6eeb97f9a0ed07391e9
|
|
BLAKE2b-256 checksum How to use checksums |
2b3a969e2bca2e1f1d891ba7e0d33c0d5fd86e493aa6b6117b9bdf66657addae
|
| 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-2.0.1-py3-none-any.whl
| Download URL | django_sastry-2.0.1-py3-none-any.whl |
|---|---|
| Size | 65.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c2a11152e9005183d1b2225be0124411e1526ac043c25085f8e0265eb6051239
|
|
BLAKE2b-256 checksum How to use checksums |
b18ebafb9de4a83ffc2be33998ec8d0d4c6ead681530582c4577dda046332a8f
|
| 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 2.0.1
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.