Django Count and Sum annotations interfere with each other
问题 While constructing a complexe QuerySet with several annotations, I ran into an issue that I could reproduce with the following simple setup. Here are the models: class Player(models.Model): name = models.CharField(max_length=200) class Unit(models.Model): player = models.ForeignKey(Player, on_delete=models.CASCADE, related_name='unit_set') rarity = models.IntegerField() class Weapon(models.Model): unit = models.ForeignKey(Unit, on_delete=models.CASCADE, related_name='weapon_set') With my test