Inspired by this gist
The class extends to calculate any percentile (not just median).
Percentile('some_field', percentile=0.5) # calculates median for the field
Percentile('some_field', percentile=0.9) # calculates the 90th percentile
For completeness, I can calculate the median age of some Student model like so:
Student.objects.aggregate(median_age=Percentile('age', percentile=0.5))
It also works when used in annotate query.
More info at the official django documentation site