再次,可能是另一个noob django问题。我的django应用程序中有这两个模型
#models.py
class Question(models.Model):
group = models.ManyToManyField(Groups)
test = models.ForeignKey(Test, on_delete=models.CASCADE)
question = models.TextField(max_length=1000)
def __str__(self):
return "{0}".format(self.question)
class Answer(models.Model):
question = models.ForeignKey(Question)
answer = models.TextField(max_length=1000)
correct = models.BooleanField()
def __str__(self):
return "{0}".format(self.answer)
我还有一个与这两个模型交互的视图
#views.py
def test_detail(request, pk):
test = get_object_or_404(Test, pk=pk)
questions = Question.objects.values('id', 'question').filter(test_id=pk).order_by('?')
answers = Answer.objects.values('answer').filter(question_id__in=list(questions))
return render(request, 'site/test.html', {'test': test, 'questions': questions, 'answers': answers})
'questions'是一个所有具有id的Question对象列表。该id也是Answer中的外键。我要做的是获取所有与“问题”列表中的任何id具有相同ID的Answer对象,
然而,这种方式会引发TypeError: int() argument must be a string, a bytes-like object or a number, not 'dict'
任何人都可以帮我指出我做错了吗?