I have a model "question" which has a one-to-many relationship with
"answer".
class Question(models.Model):
text = models.TextField()
class Answer(models.Model):
text = models.TextField()
question = models.ForeignKey(Question)
I can't figure out how to construct a filter that will give me
- just questions where there isn't an answer
- just questions where there is an answer
Is this really easy and I'm just not seeing it?
Thanks,
Jim
I could do
Answer.objects.filter(question = my_question)
but I am filtering questions on a number of parameters, such as text
of the question.
Thanks,
Jim
Question.objects.filter(answer__isnull=False)
This would give you a set of questions where an answer exists. Setting
it to True would give you a set where answers don't exist.