Let's say I have these two models:
class Test1:
...........
class Test2:
test1 = models.ForeignKey(Test1, related_name = 'tests')
isCompleted = models.BooleanField()
and I want to make this query:
queryset = Test1.objects.annotate(is_completed = ExpressionWrapper(Q(tests__isCompleted = True ),output_field = BooleanField()))
of course this is giving me a None when I do this:
queryset[0].tests.first().is_completed
What I am trying to do is I want to check if only one of the related tests
(the related objects to Test1) has a field isCompleted
with the value True
.
So my question is what's is the right way to do this?