Python Django-数据库设计

Python Django-数据库设计,python,django,database,Python,Django,Database,到目前为止,我拥有以下数据库: Person model Student model inherits from Person, no added functionality Lecturer model same as Student Course model leader = ForeignKey to Lecturer (1 Lecturer can have many courses) students = ManytoMany with Student (Many

到目前为止,我拥有以下数据库:

Person model
Student model inherits from Person, no added functionality
Lecturer model same as Student
Course model 
     leader = ForeignKey to Lecturer (1 Lecturer can have many courses)
     students = ManytoMany with Student (Many students can take many courses)
Card model
     student = OneToOne with student (1 card per 1 student).
Event model
     course = ForeignKey to Course (One course can have many events)
现在我的问题是,;我想根据以下标准对参加活动的学生进行评分。在创建事件时,标记学生需要为空。稍后,我将创建一个视图,该视图将注册一个卡ID。卡模型与学生有1-1关系。学生多,课程多。课程是一个FK到事件

  • 它们必须是与活动相关的同一课程的一部分
  • 标记的当前学生稍后需要在模型中可见

我该怎么做呢?

如果是我,我可能会使用专用的考勤表(如下所示):


如果你想要的话,你可以把学生区换成一张卡片(但是因为是一对一,这并不重要)。
present
字段的默认值也可以交换,具体取决于您希望如何处理此表中的条目。

是否有理由认为
Card
不仅仅是
Student
模型中的一列?为什么是一对一的关系?@Jonahbshop我的推理是,当卡片丢失时,它们可以被替换,但我想这也可以作为一个字段来完成。第二个原因是,我想在将来扩展该卡,以便连接到讲师进行身份验证,所以我想使用一个单独的模型啊,我明白了。有一个单独的表格是有意义的(如果卡片丢失了,你可以将它们标记为无效或其他东西)。
class Attendance(Model):
    student = models.ForeignKey('Student')
    event = models.ForeignKey('Event')
    present = models.BooleanField(default=True)