How theatlantic/django-nested-admin works
Main Architectural Components
• Core Module (nested_admin package): This is where the primary Python code resides. Key files and submodules include:
– Initialization (__init__.py)
– Compatibility, exceptions, forms, formsets, models, views, and the main nested module (nested.py)
– Templatetags integration (nested_admin/templatetags)
• Static Assets: The project includes static resources (JavaScript and CSS) along with source files inside nested_admin/static. Notice the dist/ folder (built assets) and src/ folder (the raw JS/SASS code for building the final files using webpack). This also ties in with the package.json, webpack.config.js, and npm scripts.
• Documentation: The docs directory contains Sphinx configuration files and reStructuredText documents (e.g., quickstart, API, customization, contributing) that elaborate on usage, design, and integration.
• Testing Suite: A robust and extensive test suite lies in the nested_admin/tests directory. It comprises multiple test modules that simulate different admin configurations (e.g., drag-drop, polymorphic, nested_inline levels, etc.) and include configuration files like pytest.ini, tox.ini.
• Build and Configuration: Files such as setup.py, MANIFEST.in, setup.cfg, and configuration files (.babelrc, .eslintrc.js, .nvmrc, .stylelintrc) indicate that this project integrates several build tools, linters, and testing frameworks. There also is a package-lock.json and package.json, reflecting dependencies for the JavaScript build process.
• Example/Integration Points: The README gives a concrete example of how to integrate the nested admin in a Django project by adding its URL configuration and substituting standard Django admin classes with their nested admin variants.
Component Relationships and Data Flows
• Django Admin Integration Layer:
– It interacts with “NestedModelAdmin” and the nested inline classes (for example, NestedStackedInline).
– This layer works with Django’s installed app configuration and URL routing.
• Core Business Logic and Helpers:
– Components in nested_admin (models.py, forms.py, formsets.py, etc.) are tightly interconnected to handle data validation, nesting logic, and rendering.
– The templating system (templates/ directory) is used to render the admin pages—often conditionally changed based on presence/absence of Grappelli.
• Static Assets Workflow:
– The JavaScript and CSS source files are built using webpack (configuration in webpack.config.js) and are eventually bundled into the “dist” directory.
– There’s a build dependency between the raw assets (src) and their built counterparts.
• Testing Subsystem:
– Different testing directories simulate various configurations of the nesting system. They interact with the core components to validate everything from admin widget behavior to drag-and-drop functionality.
• Documentation:
– Provides guidance on usage, configuration, and integration, which ties back to how admin and nested components should be implemented in a Django project.
Architectural Patterns and Design Principles
• Modularity: The project’s code is organized into distinct modules—separating core logic, static assets, tests, and documentation.
• Separation of Concerns: The division between Python backend code, templating (HTML/CSS), and front-end JS logic (built via webpack) clearly enforces separation.
• Build and Automation: Use of modern tools like webpack, npm, tox, pytest, and configuration files for code quality (eslint, stylelint) shows an adherence to continuous integration and automated testing.