I have two models and one of them contain a list of values that I want to count in another model.
query1= list(Model1.objects.filter(CUSTOMER=customer.id).values_list("NAME",flat=True))
print(subquery)
# [{'test1','test2,'test3','test4'}] response of query
query2=list(Model2.objects.values('CUSTOMER_NAME').annotate(Count(subquery)))
Is it possible to create all of that in one query set ? To keep the server running smoothly
NB:If one of value does not exist the second model the query should return 0 for the count of this value
Example of the return that i want to receive :
[{'name':'test1','count':7},
{'name':'test2','count':4},
{'name':'test3','count':0},
{'name':'test4','count':0},
{'name':'test5','count':2},
{'name':'test5','count':4}]