如标题所述,在 Django 中:
假设我有一个模型名称 QuestionRecord,有两个字段:full_score
和actual_score
. 我想实现SQL:
select * from QuestionRecord as QR where QR.full_score!=QR.actual_score.
也许使用原始 sql 是可以的,但我想像这样实现它:
class QuestionRecord_QuerySet(models.query.QuerySet):
def incorrect(self):# Find out those whose full_score and actual_score are not equal
return self.filter(...) # **What should I write here??**
class QuestionRecord_Manager(models.Manager):
def get_query_set(self):
return QuestionRecord_QuerySet(self.model)
class QuestionRecord(models.Model):
objects = QuestionRecord_Manager()
有什么办法吗?