django-sastry 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_sastry-1.0.0/LICENSE +22 -0
- django_sastry-1.0.0/MANIFEST.in +9 -0
- django_sastry-1.0.0/PKG-INFO +262 -0
- django_sastry-1.0.0/README.md +233 -0
- django_sastry-1.0.0/django_sastry.egg-info/PKG-INFO +262 -0
- django_sastry-1.0.0/django_sastry.egg-info/SOURCES.txt +37 -0
- django_sastry-1.0.0/django_sastry.egg-info/dependency_links.txt +1 -0
- django_sastry-1.0.0/django_sastry.egg-info/requires.txt +1 -0
- django_sastry-1.0.0/django_sastry.egg-info/top_level.txt +1 -0
- django_sastry-1.0.0/pyproject.toml +50 -0
- django_sastry-1.0.0/sastry/__init__.py +4 -0
- django_sastry-1.0.0/sastry/admin.py +3 -0
- django_sastry-1.0.0/sastry/apps.py +12 -0
- django_sastry-1.0.0/sastry/dbadmin.py +781 -0
- django_sastry-1.0.0/sastry/jinja2/base_cru.html +104 -0
- django_sastry-1.0.0/sastry/jinja2/erview/default.html +96 -0
- django_sastry-1.0.0/sastry/jinja2/s_FieldEditModal.html +17 -0
- django_sastry-1.0.0/sastry/jinja2/s_HomeLink.html +3 -0
- django_sastry-1.0.0/sastry/jinja2/s_admin.html +40 -0
- django_sastry-1.0.0/sastry/jinja2/s_cru.html +15 -0
- django_sastry-1.0.0/sastry/jinja2/s_default.html +122 -0
- django_sastry-1.0.0/sastry/jinja2/s_filter_opt.html +33 -0
- django_sastry-1.0.0/sastry/jinja2/s_pagination.html +16 -0
- django_sastry-1.0.0/sastry/jinja2/saz3.html +152 -0
- django_sastry-1.0.0/sastry/jinja2/saz3Nav.html +58 -0
- django_sastry-1.0.0/sastry/jinja2/sort_order.html +15 -0
- django_sastry-1.0.0/sastry/migrations/__init__.py +1 -0
- django_sastry-1.0.0/sastry/models.py +3 -0
- django_sastry-1.0.0/sastry/static/sastry/css/er_diagram.css +476 -0
- django_sastry-1.0.0/sastry/static/sastry/js/er_diagram.d.ts +112 -0
- django_sastry-1.0.0/sastry/static/sastry/js/er_diagram.js +864 -0
- django_sastry-1.0.0/sastry/static/sastry/js/s_crud.d.ts +66 -0
- django_sastry-1.0.0/sastry/static/sastry/js/s_crud.js +992 -0
- django_sastry-1.0.0/sastry/static/sastry/js/sastry.d.ts +1 -0
- django_sastry-1.0.0/sastry/static/sastry/js/sastry.js +21 -0
- django_sastry-1.0.0/sastry/templates/index.html +9 -0
- django_sastry-1.0.0/sastry/tests.py +88 -0
- django_sastry-1.0.0/sastry/urls.py +10 -0
- django_sastry-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Krishnamurthy (Global Multimedia)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-sastry
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A lightweight zero-config dynamic CRUD admin interface and interactive visual Entity Relations (ER) diagram for Django.
|
|
5
|
+
Author-email: Krishnamurthy <krishna@globalmultimedia.in>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/globalkrishna/django-sastry
|
|
8
|
+
Project-URL: Repository, https://github.com/globalkrishna/django-sastry.git
|
|
9
|
+
Keywords: django,admin,crud,entity-relationship,er-diagram,schema,database,orm
|
|
10
|
+
Classifier: Framework :: Django
|
|
11
|
+
Classifier: Framework :: Django :: 4.2
|
|
12
|
+
Classifier: Framework :: Django :: 5.0
|
|
13
|
+
Classifier: Framework :: Django :: 5.1
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Database
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: Django>=4.2
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# Django Sastry (django-sastry)
|
|
31
|
+
|
|
32
|
+
[](https://github.com/globalkrishna/django-sastry/actions/workflows/ci.yml)
|
|
33
|
+
[](https://opensource.org/licenses/MIT)
|
|
34
|
+
[](https://www.python.org/)
|
|
35
|
+
[](https://www.djangoproject.com/)
|
|
36
|
+
|
|
37
|
+
A lightweight, zero-configuration dynamic CRUD administration interface and interactive visual **Entity Relations (ER) Diagram** engine for Django.
|
|
38
|
+
|
|
39
|
+
<p align="center">
|
|
40
|
+
<img src="docs/images/er_diagram_preview.png" alt="Django Sastry Interactive ER Diagram" width="900" style="border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);" />
|
|
41
|
+
</p>
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Highlights & Features
|
|
46
|
+
|
|
47
|
+
1. **Interactive Visual Entity Relations (ER) Diagram**:
|
|
48
|
+
- **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.
|
|
49
|
+
- **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.
|
|
50
|
+
- **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.
|
|
51
|
+
- **Vector Connection Canvas**: Color-coded relational links with directional arrowheads for child table reverse relations and circular anchor nodes for foreign key targets.
|
|
52
|
+
- **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.
|
|
53
|
+
|
|
54
|
+
2. **Zero-Config Dynamic CRUD**:
|
|
55
|
+
- Instant spreadsheet-style data grid for all registered Django models without requiring boilerplate `admin.py` registrations.
|
|
56
|
+
- Paginated browsing, multi-field filtering, search, and inline record creation/editing.
|
|
57
|
+
- Safe foreign key resolution with query limits preventing unbounded database loads.
|
|
58
|
+
|
|
59
|
+
3. **Modular ERP Application Foundation**:
|
|
60
|
+
- Extensible base template hierarchy (`saz3.html` -> `saz3Nav.html` -> `s_home.html`) powering enterprise suites (such as `erp.saas3.in`).
|
|
61
|
+
- Easily inject custom modules into the navigation bar (Orders, Customer, Inventory, BOM, Sales, Billing).
|
|
62
|
+
- Reusable `getData` / `mdlData` backend pipelines and subclassable frontend controllers (`class CustomerController extends db_crud`) with custom action triggers (like `#ShowExtraDetail` for Orders).
|
|
63
|
+
|
|
64
|
+
4. **Lightweight & Non-Intrusive**:
|
|
65
|
+
- Introspects model structure using Django's native `Model._meta` APIs in memory with zero database queries during diagram generation.
|
|
66
|
+
- Zero external frontend dependencies: built with modern vanilla ES6 JavaScript and HTML5 Canvas.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## The Core Philosophy: The 90/10 Architecture of Database Applications
|
|
71
|
+
|
|
72
|
+
> *"Most database applications center around selecting some filtered rows, and selecting one of them to view details in a custom way."*
|
|
73
|
+
|
|
74
|
+
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.
|
|
75
|
+
|
|
76
|
+
**`django-sastry` solves this by inverting the pyramid:**
|
|
77
|
+
- **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.
|
|
78
|
+
- **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).
|
|
79
|
+
|
|
80
|
+
### The Pattern in Action: A Complete Application in ~40 Lines
|
|
81
|
+
|
|
82
|
+
#### 1. Backend: Thin View with `getData` (`views.py`)
|
|
83
|
+
```python
|
|
84
|
+
@login_required
|
|
85
|
+
def CustomersList(request, ctyp=0):
|
|
86
|
+
dat = json.loads(request.GET.get("dat", "{}"))
|
|
87
|
+
types = CustomerType.objects.all().order_by("name").values_list("id", "name")
|
|
88
|
+
if not ctyp and types:
|
|
89
|
+
ctyp = types[0][0]
|
|
90
|
+
if "filter" not in dat:
|
|
91
|
+
dat["filter"] = {"customer_type_id": ctyp}
|
|
92
|
+
dat["show"] = ["id", "customer_id", "name", "city", "state_id"]
|
|
93
|
+
|
|
94
|
+
# Sastry handles the complete query, pagination, sorting, and serialization:
|
|
95
|
+
data = getData("customer", "Customer", dat)
|
|
96
|
+
data["ctype"] = types
|
|
97
|
+
return render(request, "CustomerPage.html", data)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### 2. Frontend: Subclassing `db_crud` (`customer.ts`)
|
|
101
|
+
```typescript
|
|
102
|
+
import { db_crud } from '/static/sastry/js/s_crud.js';
|
|
103
|
+
|
|
104
|
+
class CustomerListController extends db_crud<Customer> {
|
|
105
|
+
constructor() {
|
|
106
|
+
super();
|
|
107
|
+
this.setData();
|
|
108
|
+
// Hook custom filter buttons (e.g. Retail, Wholesale, Distributor)
|
|
109
|
+
document.querySelectorAll('#FilterType a').forEach(el => {
|
|
110
|
+
el.onclick = (e) => this.filterByType(e);
|
|
111
|
+
});
|
|
112
|
+
// Enable Sastry's built-in toolbar action button for drill-down
|
|
113
|
+
const extraBtn = document.getElementById("ShowExtraDetail");
|
|
114
|
+
extraBtn.textContent = "Orders";
|
|
115
|
+
extraBtn.classList.remove('d-none');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
ShowTab(tab: string) {
|
|
119
|
+
super.ShowTab(tab);
|
|
120
|
+
if (tab !== 'ExtraDetail') return;
|
|
121
|
+
|
|
122
|
+
// Retrieve selected row from Sastry's active table
|
|
123
|
+
const indexRow = document.querySelector('#index tbody tr.table-active') as HTMLTableRowElement;
|
|
124
|
+
const customer = this.collection[indexRow.rowIndex - 1];
|
|
125
|
+
|
|
126
|
+
// Fetch and display the custom detail view for this customer:
|
|
127
|
+
fetch(`/customer/cust_order/${customer.id}/`)
|
|
128
|
+
.then(res => res.text())
|
|
129
|
+
.then(html => {
|
|
130
|
+
document.getElementById('ExtraDetail')!.innerHTML = html;
|
|
131
|
+
document.querySelector("#ExtraDetail #Bak2index")!.onclick = () => this.ShowTab('index');
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
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.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Documentation & User Manual
|
|
142
|
+
|
|
143
|
+
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:
|
|
144
|
+
|
|
145
|
+
👉 **[Comprehensive User Manual & ERP Extensibility Guide (docs/USER_MANUAL.md)](docs/USER_MANUAL.md)**
|
|
146
|
+
|
|
147
|
+
### Manual Highlights:
|
|
148
|
+
- **[Interactive Visual ER Diagram Guide](docs/USER_MANUAL.md#3-interactive-visual-er-diagram)**: Details on the right-anchored model layout, right-to-left multi-column bin packing, color conventions (Gold, Cyan, Amber), and reactive table-clicking.
|
|
149
|
+
- **[Dynamic CRUD Data Grid Guide](docs/USER_MANUAL.md#4-dynamic-crud-data-grid)**: Filtering, sorting, pagination, inline edits, and foreign key optimization.
|
|
150
|
+
- **[ERP Extensibility Guide](docs/USER_MANUAL.md#5-erp-extensibility-guide-the-erpsaas3in-architecture)**: 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]`.
|
|
151
|
+
- **[Python & JavaScript API Reference](docs/USER_MANUAL.md#7-api-reference)**: Complete function signatures and class definitions.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Installation
|
|
156
|
+
|
|
157
|
+
Install via pip:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
pip install django-sastry
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Or install directly from GitHub:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
pip install git+https://github.com/globalkrishna/django-sastry.git
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Quickstart
|
|
172
|
+
|
|
173
|
+
### 1. Add to `INSTALLED_APPS`
|
|
174
|
+
|
|
175
|
+
In your Django `settings.py`:
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
INSTALLED_APPS = [
|
|
179
|
+
# ...
|
|
180
|
+
"sastry",
|
|
181
|
+
]
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 2. Configure Jinja2 Templates
|
|
185
|
+
|
|
186
|
+
In your Django `settings.py`:
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
TEMPLATES = [
|
|
190
|
+
{
|
|
191
|
+
"BACKEND": "django.template.backends.jinja2.Jinja2",
|
|
192
|
+
"APP_DIRS": True,
|
|
193
|
+
"OPTIONS": {
|
|
194
|
+
"environment": "config.jinja2.environment",
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
199
|
+
"APP_DIRS": True,
|
|
200
|
+
# ...
|
|
201
|
+
},
|
|
202
|
+
]
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Define the standard environment helper in `config/jinja2.py`:
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
from jinja2 import Environment
|
|
209
|
+
from django.templatetags.static import static
|
|
210
|
+
from django.urls import reverse
|
|
211
|
+
|
|
212
|
+
def environment(**options):
|
|
213
|
+
env = Environment(**options)
|
|
214
|
+
env.globals.update({"static": static, "url": reverse})
|
|
215
|
+
return env
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 3. Include URLs
|
|
219
|
+
|
|
220
|
+
In your project's root `urls.py`:
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
from django.urls import path, include
|
|
224
|
+
|
|
225
|
+
urlpatterns = [
|
|
226
|
+
# ...
|
|
227
|
+
path("sastry/", include("sastry.urls")),
|
|
228
|
+
]
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### 4. Collect Static Assets
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
python manage.py collectstatic --noinput
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### 5. Access the Interfaces
|
|
238
|
+
|
|
239
|
+
Start your development server:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
python manage.py runserver
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
- **Visual ER Diagram**: Navigate to `http://127.0.0.1:8000/sastry/er/`
|
|
246
|
+
- **Dynamic CRUD Grid**: Navigate to `http://127.0.0.1:8000/sastry/`
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Security & Permissions
|
|
251
|
+
|
|
252
|
+
Access to `/sastry/` and `/sastry/er/` requires standard administrator authentication:
|
|
253
|
+
- `request.user.is_superuser` or `request.user.is_admin` must evaluate to `True`.
|
|
254
|
+
- Non-administrators receive an HTTP 403 Forbidden response.
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
MIT License. Developed by Krishnamurthy (Global Multimedia).
|
|
261
|
+
Contributions and feature suggestions are welcome!
|
|
262
|
+
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# Django Sastry (django-sastry)
|
|
2
|
+
|
|
3
|
+
[](https://github.com/globalkrishna/django-sastry/actions/workflows/ci.yml)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.python.org/)
|
|
6
|
+
[](https://www.djangoproject.com/)
|
|
7
|
+
|
|
8
|
+
A lightweight, zero-configuration dynamic CRUD administration interface and interactive visual **Entity Relations (ER) Diagram** engine for Django.
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<img src="docs/images/er_diagram_preview.png" alt="Django Sastry Interactive ER Diagram" width="900" style="border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);" />
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Highlights & Features
|
|
17
|
+
|
|
18
|
+
1. **Interactive Visual Entity Relations (ER) Diagram**:
|
|
19
|
+
- **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.
|
|
20
|
+
- **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.
|
|
21
|
+
- **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.
|
|
22
|
+
- **Vector Connection Canvas**: Color-coded relational links with directional arrowheads for child table reverse relations and circular anchor nodes for foreign key targets.
|
|
23
|
+
- **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.
|
|
24
|
+
|
|
25
|
+
2. **Zero-Config Dynamic CRUD**:
|
|
26
|
+
- Instant spreadsheet-style data grid for all registered Django models without requiring boilerplate `admin.py` registrations.
|
|
27
|
+
- Paginated browsing, multi-field filtering, search, and inline record creation/editing.
|
|
28
|
+
- Safe foreign key resolution with query limits preventing unbounded database loads.
|
|
29
|
+
|
|
30
|
+
3. **Modular ERP Application Foundation**:
|
|
31
|
+
- Extensible base template hierarchy (`saz3.html` -> `saz3Nav.html` -> `s_home.html`) powering enterprise suites (such as `erp.saas3.in`).
|
|
32
|
+
- Easily inject custom modules into the navigation bar (Orders, Customer, Inventory, BOM, Sales, Billing).
|
|
33
|
+
- Reusable `getData` / `mdlData` backend pipelines and subclassable frontend controllers (`class CustomerController extends db_crud`) with custom action triggers (like `#ShowExtraDetail` for Orders).
|
|
34
|
+
|
|
35
|
+
4. **Lightweight & Non-Intrusive**:
|
|
36
|
+
- Introspects model structure using Django's native `Model._meta` APIs in memory with zero database queries during diagram generation.
|
|
37
|
+
- Zero external frontend dependencies: built with modern vanilla ES6 JavaScript and HTML5 Canvas.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## The Core Philosophy: The 90/10 Architecture of Database Applications
|
|
42
|
+
|
|
43
|
+
> *"Most database applications center around selecting some filtered rows, and selecting one of them to view details in a custom way."*
|
|
44
|
+
|
|
45
|
+
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.
|
|
46
|
+
|
|
47
|
+
**`django-sastry` solves this by inverting the pyramid:**
|
|
48
|
+
- **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.
|
|
49
|
+
- **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).
|
|
50
|
+
|
|
51
|
+
### The Pattern in Action: A Complete Application in ~40 Lines
|
|
52
|
+
|
|
53
|
+
#### 1. Backend: Thin View with `getData` (`views.py`)
|
|
54
|
+
```python
|
|
55
|
+
@login_required
|
|
56
|
+
def CustomersList(request, ctyp=0):
|
|
57
|
+
dat = json.loads(request.GET.get("dat", "{}"))
|
|
58
|
+
types = CustomerType.objects.all().order_by("name").values_list("id", "name")
|
|
59
|
+
if not ctyp and types:
|
|
60
|
+
ctyp = types[0][0]
|
|
61
|
+
if "filter" not in dat:
|
|
62
|
+
dat["filter"] = {"customer_type_id": ctyp}
|
|
63
|
+
dat["show"] = ["id", "customer_id", "name", "city", "state_id"]
|
|
64
|
+
|
|
65
|
+
# Sastry handles the complete query, pagination, sorting, and serialization:
|
|
66
|
+
data = getData("customer", "Customer", dat)
|
|
67
|
+
data["ctype"] = types
|
|
68
|
+
return render(request, "CustomerPage.html", data)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### 2. Frontend: Subclassing `db_crud` (`customer.ts`)
|
|
72
|
+
```typescript
|
|
73
|
+
import { db_crud } from '/static/sastry/js/s_crud.js';
|
|
74
|
+
|
|
75
|
+
class CustomerListController extends db_crud<Customer> {
|
|
76
|
+
constructor() {
|
|
77
|
+
super();
|
|
78
|
+
this.setData();
|
|
79
|
+
// Hook custom filter buttons (e.g. Retail, Wholesale, Distributor)
|
|
80
|
+
document.querySelectorAll('#FilterType a').forEach(el => {
|
|
81
|
+
el.onclick = (e) => this.filterByType(e);
|
|
82
|
+
});
|
|
83
|
+
// Enable Sastry's built-in toolbar action button for drill-down
|
|
84
|
+
const extraBtn = document.getElementById("ShowExtraDetail");
|
|
85
|
+
extraBtn.textContent = "Orders";
|
|
86
|
+
extraBtn.classList.remove('d-none');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
ShowTab(tab: string) {
|
|
90
|
+
super.ShowTab(tab);
|
|
91
|
+
if (tab !== 'ExtraDetail') return;
|
|
92
|
+
|
|
93
|
+
// Retrieve selected row from Sastry's active table
|
|
94
|
+
const indexRow = document.querySelector('#index tbody tr.table-active') as HTMLTableRowElement;
|
|
95
|
+
const customer = this.collection[indexRow.rowIndex - 1];
|
|
96
|
+
|
|
97
|
+
// Fetch and display the custom detail view for this customer:
|
|
98
|
+
fetch(`/customer/cust_order/${customer.id}/`)
|
|
99
|
+
.then(res => res.text())
|
|
100
|
+
.then(html => {
|
|
101
|
+
document.getElementById('ExtraDetail')!.innerHTML = html;
|
|
102
|
+
document.querySelector("#ExtraDetail #Bak2index")!.onclick = () => this.ShowTab('index');
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
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.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Documentation & User Manual
|
|
113
|
+
|
|
114
|
+
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:
|
|
115
|
+
|
|
116
|
+
👉 **[Comprehensive User Manual & ERP Extensibility Guide (docs/USER_MANUAL.md)](docs/USER_MANUAL.md)**
|
|
117
|
+
|
|
118
|
+
### Manual Highlights:
|
|
119
|
+
- **[Interactive Visual ER Diagram Guide](docs/USER_MANUAL.md#3-interactive-visual-er-diagram)**: Details on the right-anchored model layout, right-to-left multi-column bin packing, color conventions (Gold, Cyan, Amber), and reactive table-clicking.
|
|
120
|
+
- **[Dynamic CRUD Data Grid Guide](docs/USER_MANUAL.md#4-dynamic-crud-data-grid)**: Filtering, sorting, pagination, inline edits, and foreign key optimization.
|
|
121
|
+
- **[ERP Extensibility Guide](docs/USER_MANUAL.md#5-erp-extensibility-guide-the-erpsaas3in-architecture)**: 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]`.
|
|
122
|
+
- **[Python & JavaScript API Reference](docs/USER_MANUAL.md#7-api-reference)**: Complete function signatures and class definitions.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Installation
|
|
127
|
+
|
|
128
|
+
Install via pip:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
pip install django-sastry
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Or install directly from GitHub:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
pip install git+https://github.com/globalkrishna/django-sastry.git
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Quickstart
|
|
143
|
+
|
|
144
|
+
### 1. Add to `INSTALLED_APPS`
|
|
145
|
+
|
|
146
|
+
In your Django `settings.py`:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
INSTALLED_APPS = [
|
|
150
|
+
# ...
|
|
151
|
+
"sastry",
|
|
152
|
+
]
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 2. Configure Jinja2 Templates
|
|
156
|
+
|
|
157
|
+
In your Django `settings.py`:
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
TEMPLATES = [
|
|
161
|
+
{
|
|
162
|
+
"BACKEND": "django.template.backends.jinja2.Jinja2",
|
|
163
|
+
"APP_DIRS": True,
|
|
164
|
+
"OPTIONS": {
|
|
165
|
+
"environment": "config.jinja2.environment",
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
170
|
+
"APP_DIRS": True,
|
|
171
|
+
# ...
|
|
172
|
+
},
|
|
173
|
+
]
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Define the standard environment helper in `config/jinja2.py`:
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
from jinja2 import Environment
|
|
180
|
+
from django.templatetags.static import static
|
|
181
|
+
from django.urls import reverse
|
|
182
|
+
|
|
183
|
+
def environment(**options):
|
|
184
|
+
env = Environment(**options)
|
|
185
|
+
env.globals.update({"static": static, "url": reverse})
|
|
186
|
+
return env
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 3. Include URLs
|
|
190
|
+
|
|
191
|
+
In your project's root `urls.py`:
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
from django.urls import path, include
|
|
195
|
+
|
|
196
|
+
urlpatterns = [
|
|
197
|
+
# ...
|
|
198
|
+
path("sastry/", include("sastry.urls")),
|
|
199
|
+
]
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### 4. Collect Static Assets
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
python manage.py collectstatic --noinput
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### 5. Access the Interfaces
|
|
209
|
+
|
|
210
|
+
Start your development server:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
python manage.py runserver
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
- **Visual ER Diagram**: Navigate to `http://127.0.0.1:8000/sastry/er/`
|
|
217
|
+
- **Dynamic CRUD Grid**: Navigate to `http://127.0.0.1:8000/sastry/`
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Security & Permissions
|
|
222
|
+
|
|
223
|
+
Access to `/sastry/` and `/sastry/er/` requires standard administrator authentication:
|
|
224
|
+
- `request.user.is_superuser` or `request.user.is_admin` must evaluate to `True`.
|
|
225
|
+
- Non-administrators receive an HTTP 403 Forbidden response.
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## License
|
|
230
|
+
|
|
231
|
+
MIT License. Developed by Krishnamurthy (Global Multimedia).
|
|
232
|
+
Contributions and feature suggestions are welcome!
|
|
233
|
+
|