Files
diary-system/docs/DIARY.md

94 lines
2.1 KiB
Markdown
Raw Permalink 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.
# 日记模块需求说明
_位置`backend/diary/models.py`, `frontend/index.html`
核心功能 ⭐_
---
## 📋 后端模型
### DiaryEntry 模型
```python
class DiaryEntry(models.Model):
date = DateField(unique=True) # 日期(唯一)
title = CharField(max_length=200) # 标题
completed_tasks = TextField() # 完成的任务
learned = TextField() # 学到的东西
problems = TextField() # 遇到的问题
reflections = TextField() # 想法和反思
improvements = TextField() # 进步点
plans = TextField() # 明日计划
created_at = DateTimeField() # 创建时间
updated_at = DateTimeField() # 更新时间
```
---
## 📋 API 接口
| 接口 | 方法 | 描述 |
|------|------|------|
| `/api/entries/` | GET | 获取所有日记 |
| `/api/entries/{id}/` | GET | 获取单条日记 |
| `/api/entries/` | POST | 创建日记 |
| `/api/entries/{id}/` | PUT | 更新日记 |
| `/api/entries/today/` | GET | 获取今天日记 |
| `/api/entries/recent/` | GET | 最近 7 天日记 |
| `/api/entries/stats/` | GET | 统计信息 |
---
## 🎨 前端展示
### 日历视图(主要)
- 有日记的日期显示 📝 标记
- 点击日期显示详情
- 详情包含所有字段
### 日记列表
- 按日期倒序
- 显示完整内容
---
## 🔧 修改指南
### 可以修改的
- ✅ 添加新字段
- ✅ 修改样式
- ✅ 修改 API 返回格式
- ✅ 添加新的统计维度
### 不能删除的
- ❌ DiaryEntry 模型
-`/api/entries/` 相关 API
- ❌ 日历组件
- ❌ 日记详情展示
### 添加新字段时
1. 修改 `models.py` 添加字段
2. 运行 `makemigrations diary`
3. 运行 `migrate`
4. 更新 `serializers.py`
5. 更新前端展示
6. 运行 `test_frontend.py diary`
---
## 🧪 测试清单
修改后必须验证:
- [ ] 日历正常显示
- [ ] 有日记的日期有 📝 标记
- [ ] 点击日期显示详情
- [ ] 所有字段正确显示
```bash
python3 test_frontend.py diary
```
---
_此文档必须与代码一起维护_