Django Admin Interface & Custom Views
Relevant source files
The following files were used as context for generating this wiki page:
The Django Admin Interface serves as the primary administrative control center for managing the Sunrise Communication product catalog. It provides a structured environment for administrators to manage categories, brands, and technical specifications for hardware such as CCTV and EPABX systems. The interface extends standard Django capabilities with custom views for bulk data operations, including JSON-based imports to populate the catalog efficiently.
Sources: sunrise-backend/products/admin.py:230-232, implementation_plan.md:14-16
Admin Site Configuration
The project customizes the global Django Admin site branding to reflect the Sunrise Communication identity. This configuration changes the header and index titles across the administrative dashboard.
| Configuration Element | Value |
|---|---|
| Site Header | Sunrise Communication — Admin Panel |
| Site Title | Sunrise Communication Admin |
| Index Title | Products & Solutions Management |
Sources: sunrise-backend/products/admin.py:229-231
Model Administration & Management
The system uses standard admin.ModelAdmin classes to manage the product catalog's relational data. These classes define how models are displayed, filtered, and edited within the dashboard.
Core Management Classes
- CategoryAdmin: Manages main product groups. It tracks the count of sub-categories and products associated with each category.
- BrandAdmin: Displays brand identities, including a
logo_previewfunction to show uploaded brand images directly in the list view. - ProductAdmin: The central hub for product management. It uses fieldsets to group identification, content, and visibility settings. It also integrates
ProductSpecInlineto manage technical specifications on the same page.
Sources: sunrise-backend/products/admin.py:34-118
Administrative Relationships
The following entity relationship diagram illustrates how the admin interface handles the product hierarchy and its associated specifications.
The diagram shows the hierarchical structure where Products are linked to Brands, Categories, and optional Sub-Categories, while maintaining a one-to-many relationship with Technical Specifications.
Sources: sunrise-backend/products/models.py:7-107
Custom Bulk Import System
The admin interface includes a custom view, upload_json_view, which allows administrators to perform bulk imports of product data. This system processes uploaded JSON files to automatically create or update categories, brands, sub-categories, and products.
Bulk Import Workflow
- URL Registration: The
get_urlsmethod inProductAdminadds a custom path atupload-json/. - Form Processing: The
JsonUploadFormhandles the file upload and an optionalclear_existingflag. - Data Parsing: The system parses the JSON file, supporting both a direct list of products or an object with a
"products"key. - Entity Resolution: The view uses
get_or_createlogic for Categories, Sub-Categories, and Brands. - Specification Refresh: When a product is updated, existing specifications are deleted and replaced with the new data from the JSON file.
Sources: sunrise-backend/products/admin.py:102-155
Import Logic Flow
This flowchart describes the sequential logic used by the custom upload_json_view to ingest external data.
Sources: sunrise-backend/products/admin.py:122-205
Custom Admin Templates
The project uses a custom template for the JSON upload feature, extending admin/base_site.html. This template provides a stylized user interface for the bulk import process.
Template Components
- Breadcrumbs: Standard admin navigation links including Home, Product List, and the current Upload page.
- Instructional Content: Guidance on the expected JSON format, including a code example highlighting keys like
name,brand,category, andspecs. - Safety Controls: A warning-styled checkbox for the
clear_existingoption to prevent accidental data loss. - Action Buttons: A high-visibility "Upload & Import Products" button styled with Sunrise Communication's red branding.
Sources: sunrise-backend/products/templates/admin/products/product/upload_json.html:6-50
Visual Placeholders & Metadata
The admin interface utilizes a mapping called CATEGORY_META to assign default visual attributes to categories when they are created via the JSON import.
| Category Type | Icon Class | Gradient Colors |
|---|---|---|
| Network Camera | flaticon-camera | #010c3a, #002d5b |
| Network Video Recorder | flaticon-technology | #002d5b, #0f172a |
| EPABX & Intercom | flaticon-call | #0f172a, #1e1b4b |
| Biometrics & Access | flaticon-security | #022c22, #010c3a |
Sources: sunrise-backend/products/admin.py:13-22
Summary
The Django Admin Interface & Custom Views provide a robust management layer for the Sunrise Communication catalog. By combining standard ModelAdmin configurations with custom template-driven views and JSON processing logic, the system enables rapid data entry and high-level visibility of the hardware and services catalog. Specific customizations like logo previews and category-specific metadata ensure the administrative experience aligns with the project's technical requirements and branding.
Sources: sunrise-backend/products/admin.py:229-232, implementation_plan.md:14-16