问题 I have a model in django app, with the following structure: class items(models.Model): name = models.CharField(max_length=50) location = models.CharField(max_length=3) I wanted to create a pivot table for the count of each location per each name/item, which I managed to do as per the following: queryset_res = items.objects.values('name')\ .annotate(NYC=Sum(Case(When(location='NYC', then=1),default=Value('0'),output_field=IntegerField())))\ .annotate(LND=Sum(Case(When(location='LND', then=1)