title: Getting an Aggregate Value from a Many-to-Many Field inside a Serializer
body: <p>We have an API endpoint that generates a response. However, we would like to aggregate some of the data and add an additional field to the serializer.</p>
  <pre><code>  {
          &quot;id&quot;: 61,
          &quot;not_owned_value&quot;: # This is what we're trying to get (Aggregate best_buy_price from not_owned_inventory PlayerProfiles)
          &quot;not_owned_inventory&quot;: [ # PlayerProfile objects
              &quot;29666196ed6900f07fc4f4af4738bffe&quot;,
              &quot;0ff73ca20cd787c5b817aff62e7890da&quot;,
              &quot;99d4eaef9991695d7ad94b83ad5c5223&quot;,
              &quot;6fcabe9f9c8a95980923530e7d7353a7&quot;,
              &quot;80b34c84a6e5ed25df112c11de676adc&quot;,
              &quot;0a4c5b96474f0584519d1abc4364d5a2&quot;,
              &quot;9ed1f55ac4f3b402b1d08b26870c34a6&quot;,
           ]
    }
  </code></pre>
  <p>Here is the models.py</p>
  <pre><code>class PlayerProfile(models.Model):
      card_id = models.CharField(max_length=120, unique=True, primary_key=True)
      name = models.CharField(max_length=120, null=True)
  
  class PlayerListing(models.Model):
      player_profile = models.OneToOneField(
          PlayerProfile,
          on_delete=models.CASCADE,
          null=True)
      best_buy_price = models.IntegerField(null=True)
  
  class InventoryLiveCollection(models.Model):
      not_owned_inventory = models.ManyToManyField(PlayerProfile, related_name=&quot;not_owned_inventory&quot;)
  </code></pre>
  <p>Here is the serializer.py</p>
  <pre><code>class InventoryLiveCollectionSerializer(serializers.ModelSerializer):
      not_owned_inventory = PlayerProfileAndListingForNesting(read_only=True, many=True)
  
      class Meta:
          model = InventoryLiveCollection
          fields = (
              'id',
              'date',
              'not_owned_value', # Trying to get this
              'not_owned_inventory',
          )
  </code></pre>
  <p>How can I aggregate the best_buy_price of the player_profile objects that belong to a specific InventoryLiveCollection__not_owned_inventory?</p>