You can refactor this to something like: 
```
filters = {
    'gender': {'user__profile__gender': short},
    'level_of_education': {'user__profile__level_of_education': short},
}
students = CourseEnrollment.objects.filter(course_id=course_id, **filters[feature])
distribution[short] = students.count()
```
Which is a bit more extensible.