Data Seeding & Import Tools
Relevant source files
The following files were used as context for generating this wiki page:
Data Seeding & Import Tools automate the population of the Sunrise Communication product and service catalog. These tools process structured JSON data to create database records for categories, brands, products, and technical specifications. The system supports both command-line management and administrative web uploads to ensure data consistency across development and production environments.
The import architecture bridges the Angular frontend and Django backend by using a shared products.json format. This allows developers to maintain a single source of truth for technical specifications while providing the Django admin with bulk-upload capabilities for enterprise product taxonomies.
Sources: implementation_plan.md:144-150, seed_products.py:27-35
Backend Management Command
The seed_products management command provides a CLI interface to populate the Django database from a local JSON file. It parses the products.json file located in the Angular assets directory and maps the data to the Django ORM.
Data Processing Flow
The command identifies products in the JSON file and iterates through each entry to create or retrieve related entities.
The diagram shows the logic within the seed_products.py command, including the optional record clearing and the creation of hierarchical data relationships.
Sources: seed_products.py:37-122
Configuration & Meta Mapping
The tool utilizes a CATEGORY_META mapping to assign visual attributes (icons and gradients) to categories during the import process.
| Category Name | Slug | Icon Class | Gradient Colors |
|---|---|---|---|
| Network Camera | network-camera | flaticon-camera | #010c3a, #002d5b |
| Network Video Recorder (NVR) | nvr | flaticon-technology | #002d5b, #0f172a |
| Analog HD Camera | analog-hd | flaticon-camera | #010c3a, #1e1b4b |
| EPABX & Intercom | epabx | flaticon-call | #0f172a, #1e1b4b |
| Biometrics & Access Control | biometrics | flaticon-security | #022c22, #010c3a |
Sources: seed_products.py:7-16
Administrative JSON Upload
The Django admin interface includes a custom template for bulk JSON uploads. This interface allows administrators to update the catalog without using terminal commands.
Upload Workflow
- You navigate to the "Upload Products JSON" page in the Django Admin.
- You select a
.jsonfile containing the product list. - You optionally toggle the "Clear existing" checkbox to reset the database.
- The backend processes the file using the same logic as the management command.
Sources: upload_json.html:15-38
Expected JSON Schema
The import tools require a specific JSON structure to correctly map technical specifications and service offerings.
[
{
"name": "CP Plus 4MP Dual Light Dome Camera",
"brand": "CP Plus",
"category": "CCTV Camera Systems",
"category_slug": "cctv",
"sub_category": "Dome Camera",
"short_description": "Enterprise-grade 4MP Full HD dual-light dome camera.",
"services_offered": ["Sales", "Installation", "AMC", "Repair"],
"specs": [
{ "key": "Resolution", "value": "4MP (2560 x 1440)" },
{ "key": "IR Range", "value": "30 Meters Smart IR" }
]
}
]
Sources: upload_json.html:43-62
Data Relationships & Entity Generation
The seeding tools maintain referential integrity by creating entities in a specific order. The Product entity depends on Category, SubCategory, and Brand.
The diagram illustrates the database relationships generated by the seed_products.py handler.
Sources: seed_products.py:75-122, implementation_plan.md:162-178
Integration with Frontend Discovery
Seeded data directly populates the frontend discovery layer. The SeoService uses imported product attributes to generate JSON-LD schema graphs, while the service-cluster component renders the technical specifications provided during import.
- JSON-LD Injection: The
SeoServicetakes aProductobject and extractsname,brand, andcategoryto build Schema.orgProductandBreadcrumbListnodes. - Service Cluster Rendering: The
service-cluster.component.htmlrendersauthorizedBrandsandcomparisonMatrixdata that is often mirrored or populated through these import tools.
Sources: seo.service.ts:161-205, service-cluster.component.html:48-60
Summary of Tools
| Tool | Access Point | Action | Target Models |
|---|---|---|---|
seed_products | CLI | python manage.py seed_products | All Product-related models |
| Admin Upload | Web UI | /admin/products/product/upload-json/ | All Product-related models |
--clear Flag | CLI/UI | Deletes all records before import | Product, Brand, Category, SubCategory, ProductSpec |
Sources: seed_products.py:22-26, upload_json.html:27-31