You can add GIS support to your existing project, but as you suspected, 
your current db will not be sufficient.  Unless someone knows how to 
convert an existing database, i believe you'll need to set up a new 
database from the postgis template, and move all your data to it.  That 
process might look something like this:

>From your current project, dump all your data to a json file:
$ python manage.py dumpdata --all --natural > all.json

The `natural` flag helps preserve some things like contenttypes and 
permissions.

Then switch to your new postgis template in your settings file (along with 
the other necessary items you already mentioned, like changing your backend 
to postgis).

Next:

$ python manage.py syncdb
$ python manage.py migrate # if using south
$ python manage.py loaddata all.json

You might run into an issue between syncdb and loaddata, because syncdb 
loads initial data into your tables for apps with a 
fixtures/initial_data.json file (auth, for example).  If you can use the 
dev (1.5) code, use the --no-initial-data flag.  Otherwise, you may need to 
run something like the following on your Postgres db before loaddata:

=# delete from auth_group_permissions; delete from auth_permission; delete 
from django_admin_log; delete from django_content_type;

Hope that helps.


On Monday, October 15, 2012 11:04:02 PM UTC-5, JJ Zolper wrote:
>
> Hello everyone,
>
> So I've installed GDAL, PostGIS, PROJ.4, and GEOS. I have Postgres set up 
> too.
>
> What I need help on is the logistics of getting the GeoDjango portion of 
> my website up and running. I already have my website code I'm just trying 
> to add in GeoDjango so I can handle geographic operations on the website.
>
> So I've been reading here:
>
>
> https://docs.djangoproject.com/en/1.4/ref/contrib/gis/tutorial/#introduction
>
> I see:
> Create GeoDjango 
> Project<https://docs.djangoproject.com/en/1.4/ref/contrib/gis/tutorial/#create-geodjango-project>
>
> Use the django-admin.py script like normal to create a geodjango project:
>
> $ django-admin.py startproject geodjango
>
> With the project initialized, now create a world Django application 
> within the geodjango project:
>
> $ cd geodjango$ python manage.py startapp world
>
> Configure 
> settings.py<https://docs.djangoproject.com/en/1.4/ref/contrib/gis/tutorial/#configure-settings-py>
>
> The geodjango project settings are stored in the geodjango/settings.py file. 
> Edit the database connection settings appropriately:
>
> DATABASES = {
>     'default': {
>          'ENGINE': 'django.contrib.gis.db.backends.postgis',
>          'NAME': 'geodjango',
>          'USER': 'geo',
>      }}
>
> In addition, modify the 
> INSTALLED_APPS<https://docs.djangoproject.com/en/1.4/ref/settings/#std:setting-INSTALLED_APPS>
>  setting 
> to include 
> django.contrib.admin<https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#module-django.contrib.admin>
> , 
> django.contrib.gis<https://docs.djangoproject.com/en/1.4/ref/contrib/gis/#module-django.contrib.gis>,
>  
> and world (our newly created application):
>
> INSTALLED_APPS = (
>     'django.contrib.auth',
>     'django.contrib.contenttypes',
>     'django.contrib.sessions',
>     'django.contrib.sites',
>     'django.contrib.messages',
>     'django.contrib.staticfiles',
>     'django.contrib.admin',
>     'django.contrib.gis',
>     'world')
>
>
>
> My question is do I need to start a new project if I already have one 
> project already? I already have my project "madtrak" which is the project 
> that contains my entire website. Do I need a separate project just for 
> GeoDjango? I thought that the start project command was only done once and 
> for the website. Or do I need to run "django-admin.py startproject 
> geodjango" ?
>
> If I find that I don't need to start a new project that would help a lot 
> because then I would already have a settings.py file with my installed apps 
> and an app that will have a model that connects up to the Geodjango 
> database.
>
> One more thing on this topic I see:
>
>          'ENGINE': 'django.contrib.gis.db.backends.postgis',
>
>
> Even if I don't need an entire separate project do I need to add this 
> backend to my current django project? That way I can handle all the 
> Geodjango necessities? 
>
> Because currently I have:
>
>         'ENGINE': 'django.db.backends.postgresql_psycopg2',
>
> and I would guess that is not sufficient. Any advice on handling my 
> current settings file and interfacing that with the GeoDjango database 
> would be great!
>
>
>
> Okay secondly I see this:
> Create a Spatial 
> Database<https://docs.djangoproject.com/en/1.4/ref/contrib/gis/tutorial/#create-a-spatial-database>
>
> Note
>
> MySQL and Oracle users can skip this section because spatial types are 
> already built into the database.
>
> First, a spatial database needs to be created for our project. If using 
> PostgreSQL and PostGIS, then the following commands will create the 
> database from a spatial database 
> template<https://docs.djangoproject.com/en/1.4/ref/contrib/gis/install/#spatialdb-template>
> :
>
> $ createdb -T template_postgis geodjango
>
>
> So it seems to me I need a new database because it will be a spatial 
> database for GeoDjango? I would think my current database would not be 
> sufficient because there is nothing special about it to hold the geometric 
> data I will need to process with GeoDjango. So do I need to run this 
> command and set up a new database and remove my old one? If I do this is 
> the idea that I have those extra features that I need in my spatial 
> database for GeoDjango and I then have the option on when to use that 
> functionality within each django app I build?
>
>
> Any advice regarding the integration of GeoDjango into a current django 
> project environment would be really useful!
>
> Thanks so much for your time.
>
> JJ Zolper
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/OF8Hpfm1Y-UJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to