[Django] #29422: QuerySet.extra use case - "earth_box", "ll_to_earth"

10 views
Skip to first unread message

Django

unread,
May 20, 2018, 12:12:18 PM5/20/18
to django-...@googlegroups.com
#29422: QuerySet.extra use case - "earth_box", "ll_to_earth"
-------------------------------------+-------------------------------------
Reporter: Mateusz | Owner: nobody
Kurowski |
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: 2.0
layer (models, ORM) | Keywords: QuerySet.extra,
Severity: Normal | queryset, extra, earth_box,
| ll_to_earth, models, function,
Triage Stage: | expression, manager
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
https://docs.djangoproject.com/en/2.0/ref/models/querysets/#extra

This is my use case:
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
class City(models.Model):
longitude = models.FloatField(db_index=True)
latitude = models.FloatField(db_index=True)

# this works:
City.objects.extra(where=['earth_box(ll_to_earth(%s,%s), %s) @>
ll_to_earth(latitude, longitude)'], params=[51.41816, 15.90689, 500000])
# this does not:
City.objects.extra(where=['earth_box(ll_to_earth(%s,%s), %s) @>
ll_to_earth(latitude, longitude)'], params=[F('latitude'), F('longitude'),
50000])
# psycopg2.ProgrammingError: can't adapt type 'F'

}}}
}}}

I could rewrite this in a custom Manager, but how?

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

Django

unread,
May 20, 2018, 2:07:02 PM5/20/18
to django-...@googlegroups.com
#29422: QuerySet.extra use case - "earth_box", "ll_to_earth"
-------------------------------------+-------------------------------------
Reporter: Mateusz Kurowski | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: QuerySet.extra, | Triage Stage:
queryset, extra, earth_box, | Unreviewed
ll_to_earth, models, function, |
expression, manager |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Shai Berger):

* status: new => closed
* resolution: => invalid


Comment:

Without going into too many details, I'd expect you to be able to define
two [https://docs.djangoproject.com/en/2.0/ref/models/expressions
/#writing-your-own-query-expressions user functions] (something like
`LLToBox()` taking two arguments and `LLToEarthBox()` taking three) and
use the builtin `contains` comparison, or, if this doesn't work, define
your own [https://docs.djangoproject.com/en/2.0/ref/models/lookups/
comparison].

In general, please direct such questions to the available help channels. I
am closing this ticket as invalid, for more details see
TicketClosingReasons/UseSupportChannels.

--
Ticket URL: <https://code.djangoproject.com/ticket/29422#comment:1>

Django

unread,
May 20, 2018, 6:08:57 PM5/20/18
to django-...@googlegroups.com
#29422: QuerySet.extra use case - "earth_box", "ll_to_earth"
-------------------------------------+-------------------------------------
Reporter: Mateusz Kurowski | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: QuerySet.extra, | Triage Stage:
queryset, extra, earth_box, | Unreviewed
ll_to_earth, models, function, |
expression, manager |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mateusz Kurowski):

@Shai Berger how i can use **contains**? Can you show an example queryset,
how you see it?

--
Ticket URL: <https://code.djangoproject.com/ticket/29422#comment:2>

Reply all
Reply to author
Forward
0 new messages