django queryset average of unique values

To calculate the average of unique values in a Django queryset, you can follow these steps:

  1. Use the annotate function with Count and Distinct to count the occurrences of each unique value in the queryset.
  2. Use the annotate function again to calculate the sum of the unique values.
  3. Use the aggregate function with Avg to calculate the average of the unique values.