I have an Order model, that has an origin PointField and a range IntegerField. Furthermore, there is an UserProfile model, which has a geo_location PointField. Now, I have an User instance, user. I want to select all Orders, whose distance between Order.origin and user.userprofile.geo_location is less then the value (meters) in the Order.range model field.

So again, simplified models:

class Order(models.Model):
    origin = models.PointField()
    range = models.IntegerField(blank=True, default=10000)

class UserProfile(models.Model):
    geo_location = models.PointField()

I've got this working (passing the distance statically):

>>> Order.objects.filter(origin__distance_lte=(user.profile.geo_location, D(m=3000)))

My next (unsuccessful) try was to use an F() expression to use the value from the Order.range field:

>>> Order.objects.filter(origin__distance_lte=(user.profile.geo_location, D(m=F('range'))))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/danger/devel/.virtualenvs/proj/lib/python2.7/site-packages/django/contrib/gis/measure.py", line 165, in __init__
self.m, self._default_unit = self.default_units(kwargs)
  File "/Users/danger/devel/.virtualenvs/proj/lib/python2.7/site-packages/django/contrib/gis/measure.py", line 49, in default_units
if not isinstance(value, float): value = float(value)
 TypeError: float() argument must be a string or a number

I think the problem is that the D() isn't ran lazily - I can understand that. So I tried to just take the raw value from the range field (integer) which I supposed

Edit
Report