我正在制作一个小词汇测验应用程序,一个单词的基本模型是这样的:
class Word(models.Model):
id = models.AutoField(primary_key=True)
word = models.CharField(max_length=80)
id_image = models.ForeignKey(Image)
def __unicode__(self):
return self.word
class Meta:
db_table = u'word'
我目前正在测试自己的单词模型是这样的:
class WordToWorkOn(models.Model):
id = models.AutoField(primary_key=True)
id_student = models.ForeignKey(Student)
id_word = models.ForeignKey(Word)
level = models.IntegerField()
def __unicode__(self):
return u'%s %s' % (self.id_word.__unicode__(), self.id_student.__unicode__() )
class Meta:
db_table = u'word_to_work_on'
其中“水平”表示我学得有多好。我已经学过的一组单词有这个模型:
class WordLearned(models.Model):
id = models.AutoField(primary_key=True)
id_word = models.ForeignKey(Word, related_name='word_to_learn')
id_student = models.ForeignKey(Student, related_name='student_learning_word')
def __unicode__(self):
return u'%s %s' % (self.id_word.__unicode__(), self.id_student.__unicode__() )
class Meta:
db_table = u'word_learned'
当 WordToWorkOn 上的查询集返回的结果太少时(因为它们已经学得足够好,可以移动到 WordLearned 并从 WordToWorkOn 中删除),我想找到一个 Word 来添加它。我不知道一个好方法的部分是将其限制为尚未在 WordLearned 中的单词。
所以,一般来说,我想我想对单词的查询集执行某种 .exclude() 操作,但它需要根据 WordLearned 表中的成员资格进行排除。有没有好的方法来做到这一点?我找到了很多关于加入查询集的参考资料,但找不到一个很好的关于如何做到这一点的参考资料(可能只是不知道要搜索的正确术语)。
我不想只在每个单词上使用一个标志来表示已学习、正在使用或未学习,因为最终这将是一个多用户应用程序,我不希望每个用户都有标志。因此,我认为每组有多个表会更好。
感谢所有建议。