#25499: Distance lookup not possible with a column value as distance
----------------------------------+--------------------
     Reporter:  iambibhas         |      Owner:
         Type:  New feature       |     Status:  new
    Component:  contrib.postgres  |    Version:  master
     Severity:  Normal            |   Keywords:
 Triage Stage:  Unreviewed        |  Has patch:  0
Easy pickings:  0                 |      UI/UX:  0
----------------------------------+--------------------
 Right now this is possible -

 {{{
 current_localities = Locality.objects.filter(centroid__distance_lte=(pnt,
 1000))
 }}}

 which results in -

 {{{
 (0.005) SELECT "map_locality"."id", "map_locality"."name",
 "map_locality"."slug", "map_locality"."centroid", "map_locality"."radius"
 FROM "map_locality" WHERE ST_Distan
 ce_Sphere("map_locality"."centroid",
 ST_GeomFromEWKB('\x0101000020e6100000865ad3bce3685340e9b7af03e7ec2940'::bytea))
 <= 1000 LIMIT 21;
 }}}


 But if I have a column named `radius` which has the radius for each
 Locality and `centroid` has the center point and I want to find all the
 localities that my current location falls in, I want to do something like
 this -

 {{{
 current_localities = Locality.objects.filter(centroid__distance_lte=(pnt,
 F('radius')))
 }}}

 But it's not possible right now. It generates the error -

   ProgrammingError at /api/services/
   can't adapt type 'F'

 But in reality, this is possible -

 {{{
 SELECT "map_locality"."id", "map_locality"."name", "map_locality"."slug",
 "map_locality"."centroid", "map_locality"."radius" FROM "map_locality"
 WHERE ST_Distance_Sphere("map_locality"."centroid",
 ST_GeomFromEWKB('\x0101000020e6100000865ad3bce3685340e9b7af03e7ec2940'::bytea))
 <= radius*1000 LIMIT 21;
 }}}

 Here I'm using `radius*1000` as the result of `ST_Distance_Sphere()` is in
 meter and my radius value is in km. I'm looking for suggestions on how to
 handle cases like this in the ORM, but I do think that the support for
 using a column value using `F()` would be *really* helpful.

--
Ticket URL: <https://code.djangoproject.com/ticket/25499>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.1658fc049e26327b849b50f31834e952%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to