开发者

Simply getting fields from django query set

开发者 https://www.devze.com 2023-04-09 22:51 出处:网络
class Question(models.Model): question_text = ... class Answer(models.Model): question = models.ForeignKey ...
class Question(models.Model):
  question_text = ...

class Answer(models.Model):
  question = models.ForeignKey ...
  user = models...

Basically, what I'm tryi开发者_JAVA技巧ng to do is return the set of questions that have been unanswered by the user. So basically, lets say answers = Answer.objects.exclude(user=my_user), i need to somehow do Question.objects.filter(id__in=answers.question.id). This last statement is obviously not going to work, but I hope you can get the idea.

Appreciate any help on this. Thanks.


Question.objects.exclude(id__in=[answer.question.id for answer in Answer.objects.filter(user='Joe')])
0

精彩评论

暂无评论...
验证码 换一张
取 消