'How to make calculation inside django annotate?

This one when I run generates error:

qs = UserLocation.objects.annotate(distance=0.5 - cos((F('lat')-lat1)*p)/2 + cos(lat1*p) * cos(F('lat')*p) * (1-cos((F('long')-lon1)*p))/2).all()

The error it generates is this one:

must be real number, not CombinedExpression

How can I make that calculation as an annotation



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source