You could query like this: 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. On Apr 12, 12:20 pm, Jim N <jim.nach...@gmail.com> wrote: > Just to clarify, I'm trying to filter questions that have an answer, > but I don't know the particular answer. I just want to determine > whether or not an answer object exists, with the foreign key of this > question. > > 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 > > On Apr 12, 11:50 am, Jim N <jim.nach...@gmail.com> wrote: > > > > > Hi Djangoists, > > > 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 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.