Django 2.0 (2017-12-02)

Aggregation with filter

In Django 2.0 a filter argument to aggregate functions was added to make this a lot easier:

from django.contrib.auth.models import User
from django.db.models import Count, F

User.objects.aggregate(
    total_users=Count('id'),
    total_active_users=Count('id', filter=F('is_active')),
)

Nice, short and sweet.