combine queryset with array in views ?

If you run only this part in the Django shell:

by replacing the OuterRef function with any one Employee id with more than one related Foreign_Mission, what is the content of duration?

Then what happens if you run:

What is durations after this? Is it a list with multiple elements, but all having the same value for total?

If it’s what I think it is, you may be able to replace that with:
durations = duration.annotate(total=Sum('duration_days')).values('total')[:1]
to ensure that only one value is returned.

You can find many examples of that being used in Subquery expressions here in the forum. You can do a search on "[:1]" to find them. A couple of recent examples include:

1 Like