Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
Oct 27, 2011
Jérôme Petazzoni Switch to PostGIS instead of plain PostgreSQL
The first step is to edit ``dotcloud.yml``, and replace our
plain PostgreSQL with PostGIS. Technically, PostGIS is just
PostgreSQL with additional geographic extensions. It provides
new SQL types, functions, and also a bunch of tables that
are used by PostGIS to store projection information (allowing
you to add your custom projections without recompiling or
even editing local files), as well as metadata about your
own geographic tables.

..

If you're new to PostGIS, we recommend checking out
http://postgis.refractions.net/ to get a primer about
how it works. It's not strictly necessary to work with
GeoDjango, but it can help -- just like knowing SQL is
not mandatory to work with Django, but will make you
a better Django developer.
86ab866
Jérôme Petazzoni Enable PostGIS ORM driver and GeoDjango app
To turn Django into GeoDjango, you only need two things:

* use a geographic-capable ORM engine;
* enable the ``django.contrib.gis`` application.

Since our database is PostGIS, we will use the relevant ORM engine.

..

As you can see, those two steps are easy as pie!
e10d126
Jérôme Petazzoni Add geographic app
We will now write the (possibly) simplest GeoDjango app ever.
It defines a model with a ``PointField`` and a name. Think of it
as a way to record famous landmarks. Of course, GeoDjango also has
other types, allowing to use lines, polygons, as well as collections
of those basic types. Available fields and their options are
described in the documentation at
https://docs.djangoproject.com/en/dev/ref/contrib/gis/model-api/.

Also, we will allow this app to show up in the Django admin site.
GeoDjango provides a special geographic admin, that displays
geographic fields on a map, and allows you to edit them, just like
you would edit a regular text or numeric field.

..

At that point, your first GeoDjango app is ready: push it to
DotCloud! At the end of the push, you will see the application
URL. Add "/admin" at the end of the URL, login with "admin"
and "password", and try to add something in the "Places" table!
17f352d
2  dotcloud.yml
... ...
@@ -1,4 +1,4 @@
1 1
 www:
2 2
   type: python
3 3
 db:
4  
-  type: postgresql
  4
+  type: postgis
0  hellodjango/places/__init__.py
No changes.
5  hellodjango/places/admin.py
... ...
@@ -0,0 +1,5 @@
  1
+from django.contrib.gis import admin
  2
+from models import Place
  3
+
  4
+admin.site.register(Place, admin.OSMGeoAdmin)
  5
+
8  hellodjango/places/models.py
... ...
@@ -0,0 +1,8 @@
  1
+from django.contrib.gis.db import models
  2
+
  3
+class Place(models.Model):
  4
+    def __unicode__(self):
  5
+        return self.name
  6
+    name = models.CharField(max_length=100)
  7
+    geom = models.PointField()
  8
+    objects = models.GeoManager()
4  hellodjango/settings.py
@@ -15,7 +15,7 @@
15 15
 
16 16
 DATABASES = {
17 17
     'default': {
18  
-        'ENGINE': 'django.db.backends.postgresql_psycopg2',
  18
+        'ENGINE': 'django.contrib.gis.db.backends.postgis',
19 19
         'NAME': 'template1',
20 20
         'USER': env['DOTCLOUD_DB_SQL_LOGIN'],
21 21
         'PASSWORD': env['DOTCLOUD_DB_SQL_PASSWORD'],
@@ -123,6 +123,8 @@
123 123
     'django.contrib.admin',
124 124
     # Uncomment the next line to enable admin documentation:
125 125
     # 'django.contrib.admindocs',
  126
+    'django.contrib.gis',
  127
+    'hellodjango.places',
126 128
 )
127 129
 
128 130
 # A sample logging configuration. The only tangible logging

No commit comments for this range

Something went wrong with that request. Please try again.