unforld 1 not health yet
This commit is contained in:
@@ -1,86 +1,176 @@
|
||||
# Django Admin Improvement Plan
|
||||
# Django Admin Improvement Plan - Unfold Edition
|
||||
|
||||
**Version:** 1.0.0
|
||||
**Created:** December 13, 2025
|
||||
**Status:** Planning Phase
|
||||
**Priority:** 🔴 High - 4-6 weeks implementation
|
||||
**Dependencies:** After Plan Management Implementation
|
||||
**Version:** 2.0.0
|
||||
**Created:** December 14, 2025
|
||||
**Status:** Implementation Phase
|
||||
**Priority:** 🔴 High - 3-4 weeks implementation
|
||||
**Dependencies:** After Plan Management Implementation
|
||||
**Theme:** Django Unfold (Modern Admin Theme)
|
||||
|
||||
---
|
||||
|
||||
## 🔧 CRITICAL FIXES APPLIED (December 14, 2025)
|
||||
|
||||
### Problem: Multiple Conflicting Admin Systems
|
||||
The system had **3 conflicting admin systems running simultaneously**:
|
||||
1. Default Django admin
|
||||
2. Custom IGNY8 admin modifications
|
||||
3. Unfold theme (partially installed)
|
||||
|
||||
This caused style conflicts, crashes, and inconsistent UI.
|
||||
|
||||
### Solution: Clean Unfold-Only Installation
|
||||
|
||||
**✅ Fixed Issues:**
|
||||
1. **Backend Container Crashing** - Missing `unfold` module
|
||||
- Added `django-unfold==0.73.1` to requirements.txt
|
||||
- Rebuilt Docker image: `igny8-backend:latest`
|
||||
- All containers now use new image (backend, celery_worker, celery_beat, flower)
|
||||
|
||||
2. **Admin Apps Configuration Error** - `AttributeError: module 'django.contrib.admin' has no attribute 'apps'`
|
||||
- Fixed import in `admin/apps.py`: `from django.contrib.admin.apps import AdminConfig`
|
||||
- Import Unfold AFTER apps are ready in `ready()` method
|
||||
|
||||
3. **Admin Site Inheritance** - Mixed admin systems
|
||||
- Changed `Igny8AdminSite` from `admin.AdminSite` → `UnfoldAdminSite`
|
||||
- All admin classes now inherit from Unfold's `ModelAdmin`
|
||||
|
||||
4. **Celery Admin Filters** - Using wrong filter classes
|
||||
- Changed from `DateRangeFilter` → `RangeDateFilter` (Unfold version)
|
||||
- Updated `CeleryTaskResultAdmin` to use `ModelAdmin` from Unfold
|
||||
|
||||
5. **Middleware Configuration**
|
||||
- Added `simple_history.middleware.HistoryRequestMiddleware`
|
||||
|
||||
6. **INSTALLED_APPS Order**
|
||||
- Unfold apps MUST be before `django.contrib.admin`
|
||||
- Configured properly in settings.py
|
||||
|
||||
**✅ Result: Single Clean Admin System**
|
||||
- **ONLY Unfold** - No more conflicts
|
||||
- Modern, responsive UI with Tailwind CSS
|
||||
- Dark mode support
|
||||
- Advanced filters and bulk operations built-in
|
||||
- All containers running healthy
|
||||
|
||||
---
|
||||
|
||||
## Executive Summary
|
||||
|
||||
This document outlines a comprehensive improvement plan for the IGNY8 Django Admin interface to transform it from a basic management tool into a powerful operational command center. The plan addresses UI/UX deficiencies, operational inefficiencies, missing monitoring capabilities, and organizational improvements.
|
||||
This document outlines a comprehensive improvement plan for the IGNY8 Django Admin interface using **Django Unfold**, a modern, feature-rich admin theme. Unfold provides a beautiful UI based on Tailwind CSS, advanced filtering, bulk operations, dark mode, and extensive customization options - eliminating the need for custom CSS/JS while providing enterprise-grade functionality out of the box.
|
||||
|
||||
**Key Objectives:**
|
||||
- Enhance UI styling and user experience
|
||||
- Reorganize sidebar menu for logical grouping
|
||||
- ✅ **COMPLETED:** Install and configure Unfold theme
|
||||
- Leverage Unfold's built-in features for UI/UX excellence
|
||||
- Reorganize sidebar menu using Unfold's navigation system
|
||||
- Remove unused/empty models
|
||||
- Add bulk operations and data export
|
||||
- Implement Celery task monitoring
|
||||
- Create operational dashboards
|
||||
- Improve search and filtering capabilities
|
||||
- Implement bulk operations with Unfold's action system
|
||||
- Add Celery task monitoring with Unfold integration
|
||||
- Create operational dashboards using Unfold's dashboard tools
|
||||
- Implement advanced filtering with Unfold's filter extensions
|
||||
|
||||
**What Makes This Different:**
|
||||
- **Modern UI Out-of-the-Box:** No custom CSS needed - Unfold provides beautiful, responsive design
|
||||
- **Built-in Features:** Bulk operations, advanced filters, charts, dark mode included
|
||||
- **Django Integration:** Works seamlessly with django-import-export, django-simple-history, django-celery-results
|
||||
- **Extensible:** Easy to customize with Unfold's configuration system
|
||||
|
||||
---
|
||||
|
||||
## Current State Analysis
|
||||
|
||||
### ✅ Completed (Phase 0) - December 14, 2025
|
||||
|
||||
1. ✅ **Unfold Installation** - django-unfold==0.73.1 installed in requirements.txt
|
||||
2. ✅ **Docker Image Rebuilt** - igny8-backend:latest rebuilt with all dependencies
|
||||
3. ✅ **Settings Configuration** - UNFOLD settings configured in settings.py
|
||||
4. ✅ **Admin Site Update** - Igny8AdminSite now inherits from UnfoldAdminSite
|
||||
5. ✅ **Admin Apps Fixed** - Igny8AdminConfig properly imports Unfold after apps ready
|
||||
6. ✅ **Celery Admin Updated** - CeleryTaskResultAdmin uses Unfold ModelAdmin & filters
|
||||
7. ✅ **Supporting Packages** - django-simple-history, django-import-export, django-celery-results installed
|
||||
8. ✅ **Middleware Updated** - simple_history.middleware.HistoryRequestMiddleware added
|
||||
9. ✅ **Static Files** - Unfold assets collected via collectstatic
|
||||
10. ✅ **All Containers Running** - Backend, Celery Worker, Celery Beat, Flower all healthy
|
||||
11. ✅ **Conflicts Resolved** - No more mixed admin systems (default + custom + Unfold)
|
||||
12. ✅ **Single Admin System** - **Unfold ONLY** - clean, modern, no conflicts
|
||||
|
||||
### ✅ Strengths
|
||||
|
||||
1. **Custom Admin Site** - Igny8AdminSite with logical grouping
|
||||
2. **Multi-Tenancy Support** - AccountAdminMixin and SiteSectorAdminMixin
|
||||
3. **Payment Approval Workflow** - Comprehensive payment approval system
|
||||
4. **Custom Actions** - API key generation, payment approval/rejection
|
||||
5. **Field Customization** - Custom fieldsets and readonly fields
|
||||
1. **Modern UI Theme** - Unfold provides beautiful, responsive Tailwind-based design
|
||||
2. **Custom Admin Site** - Igny8AdminSite with logical grouping (maintained)
|
||||
3. **Multi-Tenancy Support** - AccountAdminMixin and SiteSectorAdminMixin
|
||||
4. **Payment Approval Workflow** - Comprehensive payment approval system
|
||||
5. **Custom Actions** - API key generation, payment approval/rejection
|
||||
6. **Field Customization** - Custom fieldsets and readonly fields
|
||||
|
||||
### ⚠️ Issues Identified
|
||||
### ⚠️ Issues Remaining
|
||||
|
||||
#### 1. **UI/UX Problems**
|
||||
- No custom styling - uses default Django admin theme
|
||||
- Basic, dated appearance
|
||||
- Poor mobile responsiveness
|
||||
- No dashboard widgets or charts
|
||||
- Limited visual feedback for actions
|
||||
- No color coding for statuses
|
||||
|
||||
#### 2. **Sidebar Menu Organization**
|
||||
- Some groups have unclear purpose
|
||||
- "Payments" group separated from "Billing & Tenancy"
|
||||
#### 1. **Sidebar Menu Organization**
|
||||
- ✅ Current get_app_list() structure works but can be enhanced with Unfold features
|
||||
- Need to add icons to models for better visual recognition
|
||||
- Missing PlanLimitUsage model (needs to be added)
|
||||
- Some empty groups appearing
|
||||
- Inconsistent naming conventions
|
||||
|
||||
#### 3. **Unused/Empty Models**
|
||||
- **site_building** models referenced but don't exist:
|
||||
- BusinessType
|
||||
- AudienceProfile
|
||||
- BrandPersonality
|
||||
- HeroImageryDirection
|
||||
- Duplicate model registrations:
|
||||
- Invoice registered in both `business/billing/admin.py` and `modules/billing/admin.py`
|
||||
- Payment registered twice (with comment noting one shouldn't be used)
|
||||
- CreditPackage registered twice
|
||||
- CreditCostConfig registered twice
|
||||
#### 2. **Unused/Empty Models** (Same as before)
|
||||
- **site_building** models referenced but don't exist
|
||||
- Duplicate model registrations need cleanup
|
||||
|
||||
#### 4. **Missing Features**
|
||||
- No CSV/Excel export functionality
|
||||
- Limited bulk operations (only 3 actions total)
|
||||
- No Celery task monitoring interface
|
||||
- No admin dashboard with metrics
|
||||
- No data quality indicators
|
||||
- No audit trail beyond basic LogEntry
|
||||
- No advanced filtering (date ranges, etc.)
|
||||
|
||||
#### 5. **Operational Gaps**
|
||||
- No at-risk account alerts
|
||||
- No low credit warnings
|
||||
- No failed automation alerts
|
||||
- No WordPress sync status dashboard
|
||||
- No performance metrics tracking
|
||||
#### 3. **Missing Features** (Now easier with Unfold)
|
||||
- CSV/Excel export - Can use Unfold's import_export integration
|
||||
- Bulk operations - Use Unfold's enhanced action system
|
||||
- Celery monitoring - Use Unfold's contrib package for better UI
|
||||
- Admin dashboard - Use Unfold's dashboard widgets
|
||||
- Advanced filtering - Use Unfold's filter contrib package
|
||||
|
||||
---
|
||||
|
||||
## Phase 1: Critical Fixes & UI Foundation (Week 1-2)
|
||||
## Unfold Features Available
|
||||
|
||||
### Built-in Features We'll Use:
|
||||
|
||||
1. **Visual Interface**
|
||||
- Modern Tailwind CSS-based design
|
||||
- Dark mode support (automatic)
|
||||
- Responsive layout (mobile-friendly)
|
||||
- Beautiful forms and tables
|
||||
|
||||
2. **Advanced Filtering**
|
||||
- `unfold.contrib.filters` - Enhanced filter UI
|
||||
- Date range filters with calendar
|
||||
- Autocomplete filters for foreign keys
|
||||
- Numeric range filters
|
||||
|
||||
3. **Import/Export**
|
||||
- `unfold.contrib.import_export` - Styled import/export UI
|
||||
- Works seamlessly with django-import-export
|
||||
- Beautiful file upload/download interface
|
||||
|
||||
4. **History/Audit Trail**
|
||||
- `unfold.contrib.simple_history` - Enhanced history UI
|
||||
- Timeline view of changes
|
||||
- User attribution and timestamps
|
||||
|
||||
5. **Actions**
|
||||
- Enhanced bulk actions UI
|
||||
- Custom action styling
|
||||
- Progress indicators
|
||||
|
||||
6. **Dashboard Components**
|
||||
- Cards for metrics
|
||||
- Charts (Chart.js integration)
|
||||
- Custom widgets
|
||||
- Activity feeds
|
||||
|
||||
7. **Other Features**
|
||||
- Inline tabs for grouping
|
||||
- Conditional field visibility
|
||||
- WYSIWYG editor (Trix)
|
||||
- Sortable inlines
|
||||
- Command palette (Cmd+K search)
|
||||
|
||||
---
|
||||
|
||||
## Phase 1: Critical Fixes & Model Updates (Week 1)
|
||||
|
||||
### 1.1 Remove Unused Models from Admin Site
|
||||
|
||||
@@ -111,295 +201,224 @@ This document outlines a comprehensive improvement plan for the IGNY8 Django Adm
|
||||
**Files to modify:**
|
||||
- `/data/app/igny8/backend/igny8_core/business/billing/admin.py`
|
||||
|
||||
### 1.3 Reorganize Sidebar Menu Groups
|
||||
### 1.3 Update Admin Classes to Use Unfold
|
||||
|
||||
**Current Groups:**
|
||||
1. Billing & Tenancy
|
||||
2. Sites & Users
|
||||
3. Global Reference Data
|
||||
4. Planner
|
||||
5. Writer Module
|
||||
6. Thinker Module
|
||||
7. System Configuration
|
||||
8. Payments (separate!)
|
||||
9. Integrations & Sync
|
||||
10. Publishing
|
||||
11. Optimization
|
||||
12. Django Internals
|
||||
**Current State:** Most admin classes inherit from `admin.ModelAdmin`
|
||||
|
||||
**Proposed Reorganization:**
|
||||
**Action:** Update all admin classes to inherit from Unfold's ModelAdmin:
|
||||
|
||||
```python
|
||||
'💰 Billing & Accounts': {
|
||||
'models': [
|
||||
('igny8_core_auth', 'Plan'),
|
||||
('billing', 'PlanLimitUsage'), # ADD THIS
|
||||
('igny8_core_auth', 'Account'),
|
||||
('igny8_core_auth', 'Subscription'),
|
||||
('billing', 'Invoice'),
|
||||
('billing', 'Payment'),
|
||||
('billing', 'CreditTransaction'),
|
||||
('billing', 'CreditUsageLog'),
|
||||
('billing', 'CreditPackage'),
|
||||
('billing', 'PaymentMethodConfig'),
|
||||
('billing', 'AccountPaymentMethod'),
|
||||
('billing', 'CreditCostConfig'),
|
||||
],
|
||||
},
|
||||
'👥 Sites & Users': {
|
||||
'models': [
|
||||
('igny8_core_auth', 'Site'),
|
||||
('igny8_core_auth', 'Sector'),
|
||||
('igny8_core_auth', 'User'),
|
||||
('igny8_core_auth', 'SiteUserAccess'),
|
||||
('igny8_core_auth', 'PasswordResetToken'),
|
||||
],
|
||||
},
|
||||
'📚 Content Management': {
|
||||
'models': [
|
||||
('writer', 'Content'),
|
||||
('writer', 'Tasks'),
|
||||
('writer', 'Images'),
|
||||
('writer', 'ContentTaxonomy'),
|
||||
('writer', 'ContentAttribute'),
|
||||
('writer', 'ContentTaxonomyRelation'),
|
||||
('writer', 'ContentClusterMap'),
|
||||
],
|
||||
},
|
||||
'🎯 Planning & Strategy': {
|
||||
'models': [
|
||||
('planner', 'Clusters'),
|
||||
('planner', 'Keywords'),
|
||||
('planner', 'ContentIdeas'),
|
||||
('system', 'Strategy'),
|
||||
],
|
||||
},
|
||||
'🔗 Integrations & Publishing': {
|
||||
'models': [
|
||||
('integration', 'SiteIntegration'),
|
||||
('integration', 'SyncEvent'),
|
||||
('publishing', 'PublishingRecord'),
|
||||
('publishing', 'DeploymentRecord'),
|
||||
],
|
||||
},
|
||||
'🤖 AI & Automation': {
|
||||
'models': [
|
||||
('ai', 'AITaskLog'),
|
||||
('system', 'AIPrompt'),
|
||||
('automation', 'AutomationConfig'),
|
||||
('automation', 'AutomationRun'),
|
||||
('optimization', 'OptimizationTask'),
|
||||
],
|
||||
},
|
||||
'🌍 Global Reference Data': {
|
||||
'models': [
|
||||
('igny8_core_auth', 'Industry'),
|
||||
('igny8_core_auth', 'IndustrySector'),
|
||||
('igny8_core_auth', 'SeedKeyword'),
|
||||
],
|
||||
},
|
||||
'⚙️ System Configuration': {
|
||||
'models': [
|
||||
('system', 'IntegrationSettings'),
|
||||
('system', 'AuthorProfile'),
|
||||
('system', 'SystemSettings'),
|
||||
('system', 'AccountSettings'),
|
||||
('system', 'UserSettings'),
|
||||
('system', 'ModuleSettings'),
|
||||
('system', 'AISettings'),
|
||||
('system', 'ModuleEnableSettings'),
|
||||
('system', 'SystemLog'),
|
||||
('system', 'SystemStatus'),
|
||||
],
|
||||
},
|
||||
'🔧 Django System': {
|
||||
'models': [
|
||||
('admin', 'LogEntry'),
|
||||
('auth', 'Group'),
|
||||
('auth', 'Permission'),
|
||||
('contenttypes', 'ContentType'),
|
||||
('sessions', 'Session'),
|
||||
],
|
||||
},
|
||||
from unfold.admin import ModelAdmin
|
||||
from unfold.contrib.filters.admin import RangeDateFilter
|
||||
from unfold.contrib.import_export.forms import ExportForm, ImportForm
|
||||
|
||||
class TasksAdmin(SiteSectorAdminMixin, ModelAdmin):
|
||||
# Unfold-specific features
|
||||
compressed_fields = True # Compact form layout
|
||||
warn_unsaved_form = True # Warn before leaving unsaved form
|
||||
|
||||
# Standard Django admin
|
||||
list_display = ['title', 'status', 'cluster', 'created_at']
|
||||
list_filter = [
|
||||
('created_at', RangeDateFilter), # Unfold date range filter
|
||||
'status',
|
||||
]
|
||||
search_fields = ['title', 'description']
|
||||
actions_detail = ['generate_content', 'assign_cluster'] # Actions in detail view
|
||||
```
|
||||
|
||||
**Benefits:**
|
||||
- Logical grouping by functionality
|
||||
- Emoji icons for quick visual recognition
|
||||
- Combined Billing & Payments into one group
|
||||
- Separated Content Management from Planning
|
||||
- Grouped AI, Automation, and Optimization together
|
||||
- Clearer hierarchy and easier navigation
|
||||
**Key Files to Update:**
|
||||
- `/data/app/igny8/backend/igny8_core/modules/writer/admin.py`
|
||||
- `/data/app/igny8/backend/igny8_core/modules/planner/admin.py`
|
||||
- `/data/app/igny8/backend/igny8_core/modules/billing/admin.py`
|
||||
- `/data/app/igny8/backend/igny8_core/business/automation/admin.py`
|
||||
- `/data/app/igny8/backend/igny8_core/business/integration/admin.py`
|
||||
- All other admin files
|
||||
|
||||
### 1.4 Install Django Admin Enhancement Packages
|
||||
### 1.4 Add Model Icons for Visual Navigation
|
||||
|
||||
**Packages to install:**
|
||||
**Action:** Add icon declarations to each admin class using Unfold's icon system (Material Symbols):
|
||||
|
||||
```bash
|
||||
# UI Enhancement
|
||||
pip install django-admin-interface # Modern, customizable theme
|
||||
# OR
|
||||
pip install django-grappelli # Alternative mature theme
|
||||
|
||||
# Functionality
|
||||
pip install django-import-export # CSV/Excel import/export
|
||||
pip install django-admin-rangefilter # Date range filters
|
||||
pip install django-advanced-filters # Save filter combinations
|
||||
pip install django-admin-autocomplete-filter # Better autocomplete
|
||||
```python
|
||||
class AccountAdmin(AccountAdminMixin, ModelAdmin):
|
||||
# Add icon for sidebar
|
||||
icon = "business" # Material symbol name
|
||||
|
||||
class ContentAdmin(SiteSectorAdminMixin, ModelAdmin):
|
||||
icon = "article"
|
||||
|
||||
class TasksAdmin(SiteSectorAdminMixin, ModelAdmin):
|
||||
icon = "task"
|
||||
```
|
||||
|
||||
**Configuration needed:**
|
||||
- Add to INSTALLED_APPS
|
||||
- Configure static files
|
||||
- Run collectstatic
|
||||
- Apply migrations if needed
|
||||
**Icon Mapping:**
|
||||
|
||||
### 1.5 Basic UI Styling Improvements
|
||||
| Model | Icon | Material Symbol |
|
||||
|-------|------|----------------|
|
||||
| Account | business | Business/company icon |
|
||||
| Plan | card_membership | Membership card |
|
||||
| Site | language | Globe/website icon |
|
||||
| User | person | Person icon |
|
||||
| Content | article | Article/document |
|
||||
| Tasks | task | Checkbox list |
|
||||
| Clusters | bubble_chart | Cluster diagram |
|
||||
| Keywords | vpn_key | Key icon |
|
||||
| Payment | payment | Payment icon |
|
||||
| Invoice | receipt | Receipt icon |
|
||||
| Automation | settings_suggest | Automation gear |
|
||||
| Integration | integration_instructions | Integration icon |
|
||||
|
||||
**Without packages (quick wins):**
|
||||
### 1.5 Configure Unfold Colors and Branding
|
||||
|
||||
Create custom CSS file: `backend/igny8_core/static/admin/css/igny8_admin.css`
|
||||
**Already Done:** Basic UNFOLD configuration in settings.py
|
||||
|
||||
```css
|
||||
/* Status badges */
|
||||
.status-active { color: #28a745; font-weight: bold; }
|
||||
.status-inactive { color: #dc3545; }
|
||||
.status-pending { color: #ffc107; }
|
||||
**Additional Customization:**
|
||||
|
||||
/* Credit indicators */
|
||||
.credits-low { color: #dc3545; font-weight: bold; }
|
||||
.credits-medium { color: #ffc107; }
|
||||
.credits-high { color: #28a745; }
|
||||
|
||||
/* Quick action buttons */
|
||||
.admin-action-button {
|
||||
padding: 5px 15px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
margin: 2px;
|
||||
}
|
||||
|
||||
/* List view enhancements */
|
||||
.django-admin-index tr:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
```
|
||||
|
||||
Add custom template: `backend/igny8_core/templates/admin/base_site.html`
|
||||
|
||||
```html
|
||||
{% extends "admin/base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}{{ title }} | IGNY8 Admin{% endblock %}
|
||||
|
||||
{% block branding %}
|
||||
<h1 id="site-name">
|
||||
<a href="{% url 'admin:index' %}">
|
||||
IGNY8 Administration
|
||||
</a>
|
||||
</h1>
|
||||
{% endblock %}
|
||||
|
||||
{% block extrastyle %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" href="{% static 'admin/css/igny8_admin.css' %}">
|
||||
{% endblock %}
|
||||
```python
|
||||
# In settings.py UNFOLD dict
|
||||
"SITE_FAVICONS": [
|
||||
{
|
||||
"rel": "icon",
|
||||
"sizes": "32x32",
|
||||
"type": "image/png",
|
||||
"href": lambda request: static("favicons/favicon-32x32.png"),
|
||||
},
|
||||
],
|
||||
"SIDEBAR": {
|
||||
"show_search": True,
|
||||
"show_all_applications": True,
|
||||
"navigation": None, # Use get_app_list() from Igny8AdminSite
|
||||
},
|
||||
"THEME": "light", # or "dark" or "auto"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 2: Operational Features (Week 3-4)
|
||||
## Phase 2: Bulk Operations & Export (Week 2)
|
||||
|
||||
### 2.1 Add Bulk Operations
|
||||
### 2.1 Implement CSV/Excel Export with Unfold
|
||||
|
||||
**Priority Models for Bulk Actions:**
|
||||
**Install Already Complete:** django-import-export and unfold.contrib.import_export
|
||||
|
||||
**Action:** Add ExportMixin and ImportMixin to admin classes:
|
||||
|
||||
```python
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from unfold.contrib.import_export.forms import ExportForm, ImportForm, SelectableFieldsExportForm
|
||||
|
||||
class TasksAdmin(SiteSectorAdminMixin, ImportExportModelAdmin, ModelAdmin):
|
||||
import_form_class = ImportForm
|
||||
export_form_class = ExportForm
|
||||
|
||||
# Define what fields to export
|
||||
class TaskResource(resources.ModelResource):
|
||||
class Meta:
|
||||
model = Tasks
|
||||
fields = ('id', 'title', 'status', 'cluster__name', 'site__name', 'created_at')
|
||||
export_order = fields
|
||||
|
||||
resource_class = TaskResource
|
||||
```
|
||||
|
||||
**Priority Models for Export:**
|
||||
- ✅ Tasks
|
||||
- ✅ Content
|
||||
- ✅ Keywords
|
||||
- ✅ Payments
|
||||
- ✅ CreditTransactions
|
||||
- ✅ Clusters
|
||||
|
||||
### 2.2 Add Bulk Operations with Unfold Actions
|
||||
|
||||
**Unfold provides enhanced action UI automatically**
|
||||
|
||||
**Action:** Add actions to admin classes:
|
||||
|
||||
```python
|
||||
from django.contrib import admin
|
||||
from unfold.decorators import action
|
||||
|
||||
class TasksAdmin(SiteSectorAdminMixin, ModelAdmin):
|
||||
actions = ['bulk_set_in_progress', 'bulk_set_completed', 'bulk_assign_cluster']
|
||||
|
||||
@action(description="Mark as In Progress")
|
||||
def bulk_set_in_progress(self, request, queryset):
|
||||
updated = queryset.update(status='in_progress')
|
||||
self.message_user(request, f'{updated} tasks marked as in progress', 'SUCCESS')
|
||||
|
||||
@action(description="Mark as Completed")
|
||||
def bulk_set_completed(self, request, queryset):
|
||||
updated = queryset.update(status='completed')
|
||||
self.message_user(request, f'{updated} tasks completed', 'SUCCESS')
|
||||
|
||||
@action(description="Assign to Cluster", form_class=BulkAssignClusterForm)
|
||||
def bulk_assign_cluster(self, request, queryset):
|
||||
# Unfold will show form with cluster selection
|
||||
if 'cluster' in request.POST:
|
||||
cluster_id = request.POST['cluster']
|
||||
queryset.update(cluster_id=cluster_id)
|
||||
self.message_user(request, f'Assigned to cluster', 'SUCCESS')
|
||||
```
|
||||
|
||||
**Bulk Actions to Add:**
|
||||
|
||||
#### Tasks Admin
|
||||
```python
|
||||
actions = [
|
||||
'bulk_set_status_draft',
|
||||
'bulk_set_status_in_progress',
|
||||
'bulk_set_status_completed',
|
||||
'bulk_assign_cluster',
|
||||
'bulk_generate_content',
|
||||
'bulk_export_csv',
|
||||
]
|
||||
```
|
||||
- Mark as Draft
|
||||
- Mark as In Progress
|
||||
- Mark as Completed
|
||||
- Assign to Cluster
|
||||
- Generate Content (trigger AI)
|
||||
|
||||
#### Content Admin
|
||||
```python
|
||||
actions = [
|
||||
'bulk_publish_to_wordpress',
|
||||
'bulk_set_status',
|
||||
'bulk_add_taxonomy',
|
||||
'bulk_export_with_seo',
|
||||
]
|
||||
```
|
||||
- Publish to WordPress
|
||||
- Change Status
|
||||
- Add Taxonomy
|
||||
- Update SEO Settings
|
||||
|
||||
#### Keywords Admin
|
||||
```python
|
||||
actions = [
|
||||
'bulk_assign_cluster',
|
||||
'bulk_set_priority',
|
||||
'bulk_export_csv',
|
||||
]
|
||||
```
|
||||
- Assign to Cluster
|
||||
- Set Priority
|
||||
- Mark for Research
|
||||
|
||||
#### Payments Admin (already has some)
|
||||
```python
|
||||
actions = [
|
||||
'approve_payments',
|
||||
'reject_payments',
|
||||
'export_transactions', # ADD
|
||||
]
|
||||
```
|
||||
#### Payments Admin
|
||||
- Approve Payments (already exists)
|
||||
- Reject Payments (already exists)
|
||||
- Export Transactions (add)
|
||||
|
||||
### 2.2 Implement CSV Export
|
||||
### 2.3 Advanced Filtering with Unfold
|
||||
|
||||
**Install django-import-export:**
|
||||
**Unfold provides beautiful filter UI out of the box**
|
||||
|
||||
Add to each admin class:
|
||||
**Action:** Use Unfold's filter contrib for enhanced filtering:
|
||||
|
||||
```python
|
||||
from import_export.admin import ExportMixin
|
||||
from unfold.contrib.filters.admin import (
|
||||
RangeDateFilter,
|
||||
RangeDateTimeFilter,
|
||||
RangeNumericFilter,
|
||||
SingleNumericFilter,
|
||||
SliderNumericFilter,
|
||||
)
|
||||
from unfold.contrib.filters.admin import RelatedDropdownFilter, ChoicesDropdownFilter
|
||||
|
||||
class TasksAdmin(ExportMixin, SiteSectorAdminMixin, admin.ModelAdmin):
|
||||
resource_class = TaskResource # Define export fields
|
||||
# ... existing code
|
||||
```
|
||||
|
||||
**Create Resource classes for key models:**
|
||||
- TaskResource
|
||||
- ContentResource
|
||||
- KeywordsResource
|
||||
- CreditTransactionResource
|
||||
- PaymentResource
|
||||
|
||||
### 2.3 Advanced Filtering
|
||||
|
||||
**Add date range filters:**
|
||||
|
||||
```python
|
||||
from rangefilter.filters import DateRangeFilter
|
||||
|
||||
class CreditTransactionAdmin(AccountAdminMixin, admin.ModelAdmin):
|
||||
class CreditTransactionAdmin(AccountAdminMixin, ModelAdmin):
|
||||
list_filter = [
|
||||
'transaction_type',
|
||||
('created_at', DateRangeFilter),
|
||||
'account',
|
||||
('created_at', RangeDateFilter), # Beautiful date range picker
|
||||
('amount', RangeNumericFilter), # Numeric range with slider
|
||||
('account', RelatedDropdownFilter), # Dropdown with search
|
||||
('transaction_type', ChoicesDropdownFilter), # Enhanced dropdown
|
||||
]
|
||||
```
|
||||
|
||||
**Add autocomplete filters for large datasets:**
|
||||
**Filter Types to Implement:**
|
||||
|
||||
```python
|
||||
class TasksAdmin(SiteSectorAdminMixin, admin.ModelAdmin):
|
||||
autocomplete_fields = ['site', 'sector', 'cluster']
|
||||
search_fields = ['title', 'description']
|
||||
```
|
||||
| Model | Filters |
|
||||
|-------|---------|
|
||||
| CreditTransaction | Date range, Amount range, Account dropdown, Type |
|
||||
| Payment | Date range, Status, Amount range, Method |
|
||||
| Content | Date range, Status, Site, Sector, Word count range |
|
||||
| Tasks | Date range, Status, Cluster, Priority |
|
||||
| AutomationRun | Date range, Status, Site, Success/Fail |
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user