我以前试图得到这个答案,但没有运气。
我有一个看起来像(简化)的模型:
class Answer(models.model):
previous = models.ForeignKey('self')
id = IntegerField()
如何定义过滤器以查找Answer
不是previous
任何其他对象的答案的Answer
对象。
例如:
我有一组答案[A1, A2, A3, A4]
:
A1.previous = A2
A2.previous = A4
A3.previous = A1
A4.previous = A1
我想找到A3,因为这是集合中唯一一个没有X.previous = A3
X 在集合中的位置