B
B
Bobsans2019-08-28 19:14:04
PostgreSQL
Bobsans, 2019-08-28 19:14:04

How to query a database using Django ORM?

Good day.
Will face the problem of selecting from the database using PostgreSQL functions. Postgres has a "poly_contain_pt" function that checks whether a point is in a polygon. And there is data: polygon points.
There is a record model, of the form:

class Record:
    name = models.CharField(max_length=255)
    location = LocationField()

LocationField added himself. This is a Post-Ress ARRAY with two elements (x, y).
I got something like this, it works:
SELECT * FROM record 
WHERE poly_contain_pt(
    POLYGON(PATH '((56,28),(56,30),(55,31),(54,31),(54,32),(53,32),(53,33),(52,32,(52,32))'), 
    POINT(location[2], location[1])
);

Can Django ORM describe this somehow? I found little in the documentation, in Google a lot of things are no longer working. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Guest007, 2019-08-28
@Guest007

Django + PostGIS = https://docs.djangoproject.com/en/2.2/ref/contrib/...
Crossed together wonderfully. Immediately and the corresponding fields in the models and geo-methods are available without dancing with a tambourine. Calculation of the occurrence of a point in a figure and so on - at a time. I did. So you can not fence your own. Well, if you really want to.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question