
功能特性: - JWT用户认证系统 - 日报CRUD管理 - 三级权限控制 - 多维度搜索过滤 - 统计分析功能 - 评论互动系统 - 响应式Cool Admin界面 - 暗色主题支持 技术栈: - 后端:Django 4.2.7 + DRF + SimpleJWT - 前端:Vue 3 + Element Plus + Pinia - 数据库:SQLite/PostgreSQL - 部署:Docker + Nginx 包含内容: - 完整的后端API代码 - 现代化前端界面 - 数据库迁移文件 - 部署脚本和文档 - 演示页面和测试工具
97 lines
3.4 KiB
Python
97 lines
3.4 KiB
Python
from django.contrib import admin
|
|
from django.utils.html import format_html
|
|
from .models import DailyReport, ReportComment
|
|
|
|
|
|
@admin.register(DailyReport)
|
|
class DailyReportAdmin(admin.ModelAdmin):
|
|
"""日报管理"""
|
|
list_display = (
|
|
'id', 'user_info', 'report_date', 'work_summary_short',
|
|
'next_day_plan_short', 'is_draft', 'created_at'
|
|
)
|
|
list_filter = ('is_draft', 'report_date', 'created_at')
|
|
search_fields = ('user__username', 'user__first_name', 'user__last_name',
|
|
'work_summary', 'next_day_plan')
|
|
date_hierarchy = 'report_date'
|
|
ordering = ('-report_date', '-created_at')
|
|
readonly_fields = ('created_at', 'updated_at')
|
|
|
|
fieldsets = (
|
|
('基本信息', {
|
|
'fields': ('user', 'report_date', 'is_draft')
|
|
}),
|
|
('日报内容', {
|
|
'fields': ('work_summary', 'next_day_plan', 'difficulties', 'suggestions')
|
|
}),
|
|
('时间信息', {
|
|
'fields': ('created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
def user_info(self, obj):
|
|
"""显示用户信息"""
|
|
return format_html(
|
|
'<strong>{}</strong><br><small>{} | {}</small>',
|
|
obj.user.username,
|
|
obj.user.department or '未设置部门',
|
|
obj.user.position or '未设置职位'
|
|
)
|
|
user_info.short_description = '用户信息'
|
|
|
|
def work_summary_short(self, obj):
|
|
"""工作总结简短显示"""
|
|
return obj.work_summary[:50] + '...' if len(obj.work_summary) > 50 else obj.work_summary
|
|
work_summary_short.short_description = '工作总结'
|
|
|
|
def next_day_plan_short(self, obj):
|
|
"""明日计划简短显示"""
|
|
return obj.next_day_plan[:50] + '...' if len(obj.next_day_plan) > 50 else obj.next_day_plan
|
|
next_day_plan_short.short_description = '明日计划'
|
|
|
|
def get_queryset(self, request):
|
|
"""优化查询"""
|
|
return super().get_queryset(request).select_related('user')
|
|
|
|
|
|
@admin.register(ReportComment)
|
|
class ReportCommentAdmin(admin.ModelAdmin):
|
|
"""日报评论管理"""
|
|
list_display = ('id', 'report_info', 'user', 'content_short', 'created_at')
|
|
list_filter = ('created_at', 'user')
|
|
search_fields = ('user__username', 'content', 'report__user__username')
|
|
ordering = ('-created_at',)
|
|
readonly_fields = ('created_at', 'updated_at')
|
|
|
|
fieldsets = (
|
|
('基本信息', {
|
|
'fields': ('report', 'user')
|
|
}),
|
|
('评论内容', {
|
|
'fields': ('content',)
|
|
}),
|
|
('时间信息', {
|
|
'fields': ('created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
def report_info(self, obj):
|
|
"""显示日报信息"""
|
|
return format_html(
|
|
'<strong>{}</strong><br><small>{}</small>',
|
|
f'{obj.report.user.username} - {obj.report.report_date}',
|
|
obj.report.work_summary[:30] + '...' if len(obj.report.work_summary) > 30 else obj.report.work_summary
|
|
)
|
|
report_info.short_description = '关联日报'
|
|
|
|
def content_short(self, obj):
|
|
"""评论内容简短显示"""
|
|
return obj.content[:50] + '...' if len(obj.content) > 50 else obj.content
|
|
content_short.short_description = '评论内容'
|
|
|
|
def get_queryset(self, request):
|
|
"""优化查询"""
|
|
return super().get_queryset(request).select_related('user', 'report__user')
|