seaislee1209 1e94241587 feat: multi-project per sub-account support
Data model:
- Add IAMUserProject model (sub-account → N projects, each with monitoring toggle)
- Remove old single project_name from IAMUser model
- Update SpendingRecord with per-project granularity

Backend:
- Project CRUD views: list/add/update-toggle/delete/toggle-all
- Create user view auto-adds first project if specified
- Scheduler aggregates spending across all enabled projects per user
- Per-project spending recorded in SpendingRecord + IAMUserProject.current_spending
- Alert details include per-project spending breakdown

Frontend:
- New "项目管理" dialog: add projects from Volcengine dropdown, toggle monitoring per project, remove projects, batch toggle all
- "项目" column in user table showing monitored/total count (clickable)
- BillingView: expandable rows showing per-project spending breakdown
- Create dialog: optional initial project selection
- Removed old single-project select from config dialog

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 20:37:38 +08:00

48 lines
1.5 KiB
Python

from django.contrib import admin
from .models import VolcAccount, IAMUser, IAMUserProject, GlobalConfig, AlertRecord, SpendingRecord, QuotaAllocation
@admin.register(VolcAccount)
class VolcAccountAdmin(admin.ModelAdmin):
list_display = ('name', 'access_key_hint', 'is_active', 'updated_at')
class IAMUserProjectInline(admin.TabularInline):
model = IAMUserProject
extra = 0
@admin.register(IAMUser)
class IAMUserAdmin(admin.ModelAdmin):
list_display = ('username', 'display_name', 'status', 'monitor_enabled',
'allocated_quota', 'consumed_total')
list_filter = ('status', 'monitor_enabled')
inlines = [IAMUserProjectInline]
@admin.register(IAMUserProject)
class IAMUserProjectAdmin(admin.ModelAdmin):
list_display = ('iam_user', 'project_name', 'monitor_enabled', 'current_spending')
list_filter = ('monitor_enabled',)
@admin.register(QuotaAllocation)
class QuotaAllocationAdmin(admin.ModelAdmin):
list_display = ('iam_user', 'amount', 'total_after', 'created_by', 'created_at')
@admin.register(GlobalConfig)
class GlobalConfigAdmin(admin.ModelAdmin):
list_display = ('monitor_interval_seconds', 'updated_at')
@admin.register(AlertRecord)
class AlertRecordAdmin(admin.ModelAdmin):
list_display = ('title', 'alert_type', 'spending_amount', 'notified', 'created_at')
list_filter = ('alert_type', 'notified')
@admin.register(SpendingRecord)
class SpendingRecordAdmin(admin.ModelAdmin):
list_display = ('iam_user', 'project_name', 'bill_period', 'amount', 'updated_at')