Answer the question
In order to leave comments, you need to log in
Should I use django.contrib.gis.db.backends.postgis for the entire project?
In a Django project , there are jobs that are attached to certain coordinates. It is necessary to implement sorting of tasks by distance from the user to the task. It was decided to use PostGIS for this , but after reading the documentation , it became clear that to work with PostGIS , you need to use the django.contrib.gis.db.backends.postgis engine :
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'geodjango',
'USER': 'geo',
}
}
CREATE OR REPLACE FUNCTION distance(lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT) RETURNS FLOAT AS $$
DECLARE
x float = 69.1 * (lat2 - lat1);
y float = 69.1 * (lon2 - lon1) * cos(lat1 / 57.3);
BEGIN
RETURN sqrt(x * x + y * y);
END
$$ LANGUAGE plpgsql;
Answer the question
In order to leave comments, you need to log in
There was a similar task. After reading everything you can, I did not find the answer. I decided to check myself how it will be with one base.
1. Under the geo data, I made a separate application app_geo.
2. I found on the internet that django.contrib.gis.db.models is inherited from django.db.models, so I wrote in this app in models.py
from django.contrib.gis.db import models
from django.db import models
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question