I have an Order model, that has an origin PointField and a range IntegerField. Furthermore, there is an UserProfile model
I think you're going to have to drop some SQL in to do what you want, as the GeoDjango helpers don't have a way of you making a suitable Distance object that is simultaneously a Django F object (ie field lookup). You don't say which database you're using, but here's how you do it with PostGIS:
Order.objects.all().extra(
where=['ST_Distance(origin, ST_PointFromText(%s, 4326)) <= CAST(range AS double precision) / 1000'],
params=[user.profile.geo_location.wkt]
)
Let's explain what's happening here, because it's pretty thorny. Going from the left:
.extra() allows you to add extra fields and restrictions into a query; here we're adding a restrictiondistance_lte operator converts into (from the Django documentation)4326 is the default SRID for Django, but not for PostGIS so we have to specify itPoint fields have an accessor .wkt which gives their WKT representation, which we needed earlier in our ST_PointFromText() callNote that according to the PostGIS documentation, ST_Distance() doesn't use indexes, so you may want to investigate using ST_DWithin() instead (it's documented right after ST_Distance()).