Don't waste too much time trying finesse a cool SQL solution.
from collections import defaultdict
count_cat_code = defaultdict(int)
count_unique_code = defaultdict(int)
count_combo_code = defaultdict(int)
for obj in Item.objects.all():
count_cat_code[obj.category_code] += 1
count_unique_code[obj.unique_code] += 1
count_combo_code[obj.category_code,obj.unique_code] += 1
That will do it. And it will work reasonably quickly. Indeed, if you do some benchmarking, you may find that -- sometimes -- it's as fast as a "pure SQL" statement.
[Why? Because RDBMS must use a fairly inefficient algorithm for doing GROUP BY and Counts. In Python we have the luxury of assuming some things based on our application and
our knowledge of the data. In this case, for example, I assumed that it would all fit
in memory. An assumption that cannot be made by the RDBMS internal algorithms.]