2012-02-16 35 views
1

我有一個Question模型和一個Response模型,它包含一個外鍵到Question如何在查詢中使用Django外鍵集?

我能得到所有響應與question.response_set

我想要做一些事情來的

Question.objects.exclude(response_set=None) 

什麼是去最好的辦法效果給定的問題嗎?

回答

4
Question.objects.exclude(response__isnull=True) 

應該只返回與答覆的問題

+0

HM,Q = Question.objects.exclude(response__isnull = TRUE).exclude(response__skipped = TRUE)返回比提問= Response.objects略有不同的一些問題.exclude(跳過=真).distinct( 'question__id')。values_list( 'question__id',扁平=真) 打印LEN(問題) 指數= randint(1,LEN(問題)) QID =問題[index] question = Question.objects.get(pk = qid) 你爲什麼認爲這是? – Colleen 2012-02-17 00:05:51