Skip to content

Instantly share code, notes, and snippets.

@dracos
Created May 14, 2012
Embed
What would you like to do?
Installing a new GeoDjango project on my Mac
sudo port install python27
sudo port install postgresql91
sudo port install postgresql91-server
sudo port install postgis
# Will now install psycopg2 system wide with ports, but could have done it later in the virtualenv
sudo port install py-psycopg2 +postgresql91
# follow instructions printed by the above to set up a database
sudo mkdir -p /opt/local/var/db/postgresql91/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql91/defaultdb
sudo su postgres -c '/opt/local/lib/postgresql91/bin/initdb -D /opt/local/var/db/postgresql91/defaultdb'
# Start up the database
sudo su - postgres -c "/opt/local/lib/postgresql91/bin/pg_ctl start -D /opt/local/var/db/postgresql91/defaultdb"
$PATH=/opt/local/lib/postgresql91/bin:$PATH
# Create the postgis template, from GeoDjango install page.
POSTGIS_SQL_PATH=`pg_config --sharedir`/contrib/postgis-1.5
createdb -E UTF8 template_postgis # Create the template spatial database.
createlang -d template_postgis plpgsql # Adding PLPGSQL language support.
psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"
psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql # Loading the PostGIS SQL routines
psql -d template_postgis -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql
psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;" # Enabling users to alter spatial tables.
psql -d template_postgis -c "GRANT ALL ON geography_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
createdb -T template_postgis django_geotest
# Okay, I think that's setup done. Now let's do Django.
cd ~/Projects
mkdir PhilTest
cd PhilTest
mkvirtualenv --distribute --python=/opt/local/bin/python2 PhilTest
pip install django
django-admin.py startproject philtest
cd philtest
python manage.py startapp points
vim philtest/settings.py # Database set up of: django.contrib.gis.db.backends.postgis / django_geotest / postgres
# Added django.contrib.admin, django.contrib.gis, points to INSTALLED_APPS
vim philtest/urls.py # Set up admin stuff, using django.contrib.gis
vim points/models.py points/admin.py # Model using django.contrib.gis that just has a PointField, standard admin using django.contrib.gis.
python manage.py syncdb
python manage.py runserver
# Visit http://localhost:8000/admin/ log in, add point.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment