About Creating Spatial Postgres Database
To use spatial features like distance calculation between points with the Postgres database, you need PostGIS extension. It has to be activated for each Postgres database individually. On MacOS, you can install the database management system and extension with Homebrew:
$ brew install postgres
$ brew install postgis
$ brew services start postgres
Create the user and database for a new project and activate the PostGIS extension with these commands:
$ createuser --createdb --password myprojectuser
$ createdb --username=myprojectuser myprojectdb
$ psql myprojectdb
> CREATE EXTENSION postgis;
Then use "django.contrib.gis.db.backends.postgis"
as the database backend in your Django project settings:
DATABASES = {
"default": {
"ENGINE": "django.contrib.gis.db.backends.postgis",
"NAME": "myprojectdb",
"USER": "myprojectuser",
"PASSWORD": "secretpassword",
"HOST": "127.0.0.1",
"PORT": "5432",
}
}
Tips and Tricks Programming Dev Ops Databases Django 5.x Django 4.2 Django 3.2 PostgreSQL PostGIS
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.