The same issue, unfortunately.
Apparently you can’t use the ‘F’ function in an aggregation. (I don’t think I ever realized that.)
If you only need the range of values, you can do this:
q = Choice.objects.filter(question_id=133).aggregate(
weight_range=Max('choice_weight') - Min('choice_weight')
)
If you need the range of values along with the max and min values, you can still do this:
q = Choice.objects.filter(question_id=133).aggregate(
max_weight=Max('choice_weight'),
min_weight=Min('choice_weight'),
weight_range=Max('choice_weight') - Min('choice_weight')
)