i want to get the count of the user id of this table according to the columns approval_transaction_type and approval_type.
the expected result of this would be.
Approval Transaction Type ID (60)
- Approval Type ID (65) = 2 Users
- Approval Type ID (64) = 2 Users
- Approval Type ID (63) = 2 Users
- Approval Type ID (62) = 2 Users
- Approval Type ID (61) = 2 Users
My current code to achieve is this, but it overwrites the sub list and returns the incorrect result(Which i don't understand why the last array will overwrite all the array):
for transaction in transaction_types:
# Initial Array
transaction["approval_types"] = []
for approval_type in approval_types:
# Get Count of Users
approval_type["count"] = Model.objects.filter(approval_transaction_type=transaction['id'],approval_type=approval_type['id']).values().count()
# Assign this sub list to main list
transaction["approval_types"].append(approval_type)
How do i get the count without looping and use the queryset? Let me know if something is not clear about this. Thanks!