【发布时间】:2021-12-24 16:21:41
【问题描述】:
我正在为一个电子学习项目设计一个 API。该平台使学生能够参加在线考试。测试包含问题,问题可以有多个选项。以下是我的应用的架构:
Test:
id: Primary Key
duration: Integer
created: Timestamp
Question:
id: Primary Key
serial: Integer
test: Foreign Key (Test)
body: Char Field
Option:
id: Primary Key
question: Foreign Key (Question)
body: Char Field
correct: Boolean Field
StudentSelectedOption:
id: Primary Key
question: Foreign Key (Question)
student: Foreign Key (User)
option: Foreign Key (Option)
现在,问题是我想创建一个端点,用于根据请求用户返回学生选择的选项
/test/<int:test_id>/student-answers/
例如,如果任何用户想要获得他们对测试 id 1 的答案,他们将转到 /test/1/student-answers/ (用户将从请求对象中提取,因为我正在使用令牌身份验证)
但我无法过滤与测试 ID 和用户相关的选定选项。有人可以帮帮我吗?
【问题讨论】:
-
你能添加一个你想要的有效网址吗?类似于 /test/2/studen-answers/3
-
@Rvector 我已经更新了问题,非常感谢
标签: django django-models django-rest-framework