多对多关系并检查成员资格
我希望创建一个具有以下模型和约束的数据库。
1) Student with attributes name, roll number
2) Exam with attributes exam_code, exam_subject
3) Option with attributes option_name, and ManyToManyField on Exam
4) Application with user, exam, ManyToManyField on Options(new)
基本上会有很多考试和选择。学生有权选择与其考试选择相关的选项子集。
编辑:使用新模型应用程序,我想问题归结为使用 界面中的 JavaScript 用于限制界面中可用的选项。
下一个挑战在于处理具有多个科目的学生,并且他们的选项子集应该是可用于两种考试的选项的交集(因为两种不同的考试可能有共同的选项)。关于这部分的任何指导都会很棒。
I wish to create with a database with following models and constraints.
1) Student with attributes name, roll number
2) Exam with attributes exam_code, exam_subject
3) Option with attributes option_name, and ManyToManyField on Exam
4) Application with user, exam, ManyToManyField on Options(new)
Basically there will be many exams and options. Student is entitled to choose a subset of options pertaining to his examination choice.
edit: With the new model Application, I suppose the problem boils down to using javascript in the interface for limiting the options available in the interface.
The next challenge lies in handling students with multiple subjects and their subset of options should be a intersection of options(as two different exams might have options in common) available for both exams. Any guidance on this part would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就目前情况而言,学生并没有真正参与其中。重要的是对于所讨论的特定考试有哪些选项可用(学生只是名义上相关,因为特定考试是其数据点)。
因此,在这种情况下,学生的可用选项始终取决于:
您可能想要的是学生能够参加多次考试,然后获得所有所有参加的考试的可用选项——一种汇总。
如果是这种情况,首先,您需要在学生和考试之间建立 M2M 关系(而不是外键)。然后,您可以通过以下方式获取所有考试的所有可用选项:
As it stands right now, the Student doesn't really play into the equation. All that matters is what options are available for the particular exam in question (where Student is only nominally related in that the particular exam is a data point on it).
So, that being the case, the available options to a student is always a function of:
What you may be wanting, is the ability for a student to have taken multiple exams, and then have all of the available options for all of the exams taken -- a sort of aggregate.
If that's the case, first, you would require a M2M relationship established between Student and Exam (instead of the Foreign Key). Then, you could get all available options from all exams via: