基于条件的Concat Queryset?

时间:2018-03-03 17:48:40

标签: django django-models django-queryset django-1.11

假设我有跟随QuestionAnswer

等模型
class Question(models.Model):
     category = models.ForeignKey(Category)

#contains all the choices of questions
class Options(models.Model):
     question = models.Foreignkey(Question)

#contains question, choice choosen by user, category
class Answer(models.Model):
     question = models.Foreignkey(Question)
     option = models.ForeignKey(Option)
     category = models.ForeignKey(Category)

我的查询集如下

questions = Question.objects.filter(category_id=1)
answers = Answer.objects.filter(category_id=1)

questions查询集包含所有类别问题,answers查询集包含每user个问题的所有答案。现在我想显示所有问题的答案和警告信息到未答复的问题,实现这一目标的最佳方法是什么?

0 个答案:

没有答案