django-vue3-admin-backend/crud_book/README_MIGRATION.md
2025-10-22 22:43:03 +08:00

59 lines
1.3 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.

# 数据库迁移说明
## 新增字段和模型
本次更新为图书管理系统添加了以下功能:
### 1. CrudBookModel 新增字段
- `file`: 电子书文件字段FileField
- `file_type`: 文件类型字段CharField用于标识文件格式epub, pdf, mobi等
### 2. 新增 ReadingProgress 模型
用于记录用户的阅读进度,包含以下字段:
- `user`: 用户外键
- `book`: 图书外键
- `location`: 阅读位置EPUB CFI 或其他位置标识)
- `progress`: 阅读进度百分比0-100
## 执行迁移
在后端项目目录下执行以下命令:
```bash
# 生成迁移文件
python manage.py makemigrations crud_book
# 执行迁移
python manage.py migrate crud_book
```
## 新增API接口
### 1. 获取图书文件
```
GET /api/CrudBookModelViewSet/{id}/file/
```
返回图书的电子文件URL和文件类型
### 2. 保存阅读进度
```
POST /api/reading-progress/
{
"book_id": 1,
"location": "epubcfi(...)",
"progress": 45.5
}
```
### 3. 获取阅读进度
```
GET /api/reading-progress/{book_id}/
```
返回指定图书的阅读进度
## 注意事项
1. 确保在 Django settings.py 中配置了 MEDIA_ROOT 和 MEDIA_URL
2. 需要配置静态文件服务以访问上传的电子书文件
3. 阅读进度按用户和图书唯一,同一用户同一本书只有一条进度记录