Files
jiangmingzhao-daily-report/backend/daily_report/models.py
jiangmingzhao 9b9ee273fc 初始提交:企业级日报系统完整代码
功能特性:
-  JWT用户认证系统
-  日报CRUD管理
-  三级权限控制
-  多维度搜索过滤
-  统计分析功能
-  评论互动系统
-  响应式Cool Admin界面
-  暗色主题支持

 技术栈:
- 后端:Django 4.2.7 + DRF + SimpleJWT
- 前端:Vue 3 + Element Plus + Pinia
- 数据库:SQLite/PostgreSQL
- 部署:Docker + Nginx

 包含内容:
- 完整的后端API代码
- 现代化前端界面
- 数据库迁移文件
- 部署脚本和文档
- 演示页面和测试工具
2025-09-13 14:35:15 +08:00

90 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.db import models
from django.contrib.auth import get_user_model
from django.core.validators import MinLengthValidator
User = get_user_model()
class DailyReport(models.Model):
"""日报模型"""
user = models.ForeignKey(
User,
on_delete=models.CASCADE,
verbose_name="提交人",
related_name='daily_reports'
)
work_summary = models.TextField(
"工作总结",
validators=[MinLengthValidator(10, message="工作总结至少需要10个字符")]
)
next_day_plan = models.TextField(
"明日计划",
validators=[MinLengthValidator(10, message="明日计划至少需要10个字符")]
)
difficulties = models.TextField(
"遇到的困难",
blank=True,
null=True,
help_text="可选:描述工作中遇到的问题或困难"
)
suggestions = models.TextField(
"建议或意见",
blank=True,
null=True,
help_text="可选:对工作或团队的建议"
)
report_date = models.DateField("日报日期", help_text="填写日报对应的日期")
created_at = models.DateTimeField("提交时间", auto_now_add=True)
updated_at = models.DateTimeField("更新时间", auto_now=True)
is_draft = models.BooleanField("草稿状态", default=False, help_text="是否为草稿")
class Meta:
verbose_name = "日报"
verbose_name_plural = verbose_name
ordering = ['-report_date', '-created_at']
unique_together = [['user', 'report_date']] # 每个用户每天只能有一份日报
indexes = [
models.Index(fields=['user', 'report_date']),
models.Index(fields=['report_date']),
models.Index(fields=['-created_at']),
]
def __str__(self):
return f'{self.user.username} - {self.report_date}'
@property
def work_summary_preview(self):
"""工作总结预览前100个字符"""
return self.work_summary[:100] + '...' if len(self.work_summary) > 100 else self.work_summary
@property
def next_day_plan_preview(self):
"""明日计划预览前100个字符"""
return self.next_day_plan[:100] + '...' if len(self.next_day_plan) > 100 else self.next_day_plan
class ReportComment(models.Model):
"""日报评论模型"""
report = models.ForeignKey(
DailyReport,
on_delete=models.CASCADE,
related_name='comments',
verbose_name="关联日报"
)
user = models.ForeignKey(
User,
on_delete=models.CASCADE,
verbose_name="评论人"
)
content = models.TextField("评论内容")
created_at = models.DateTimeField("评论时间", auto_now_add=True)
updated_at = models.DateTimeField("更新时间", auto_now=True)
class Meta:
verbose_name = "日报评论"
verbose_name_plural = verbose_name
ordering = ['-created_at']
def __str__(self):
return f'{self.user.username} 评论了 {self.report}'