diff --git a/README.rst b/README.rst index 88f8008..3871ddd 100644 --- a/README.rst +++ b/README.rst @@ -33,6 +33,12 @@ If you're using `south `_: 'default': 'south.db.postgresql_psycopg2' } +If you use PostGIS (django.contrib.gis.db.backends.postgis): + +:: + + DATABASE_POOL_POSTGIS = True + Everything should work as expected. @@ -70,4 +76,4 @@ Check out the official `SQLAlchemy Connection Pooling `_ for 1.3 support. \ No newline at end of file +django-postgrespool currently supports Django 1.4 and greater. See `this ticket `_ for 1.3 support. diff --git a/django_postgrespool/base.py b/django_postgrespool/base.py index d701467..6a15485 100644 --- a/django_postgrespool/base.py +++ b/django_postgrespool/base.py @@ -8,10 +8,17 @@ from psycopg2 import InterfaceError, ProgrammingError, OperationalError from django.conf import settings -from django.db.backends.postgresql_psycopg2.base import * -from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper as Psycopg2DatabaseWrapper -from django.db.backends.postgresql_psycopg2.base import CursorWrapper as DjangoCursorWrapper -from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation as Psycopg2DatabaseCreation + +if getattr(settings, 'DATABASE_POOL_POSTGIS', False): + from django.contrib.gis.db.backends.postgis.base import * + from django.contrib.gis.db.backends.postgis.base import DatabaseWrapper as BaseDatabaseWrapper + from django.contrib.gis.db.backends.postgis.base import CursorWrapper as DjangoCursorWrapper + from django.contrib.gis.db.backends.postgis.creation import DatabaseCreation as BaseDatabaseCreation +else: + from django.db.backends.postgresql_psycopg2.base import * + from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper as BaseDatabaseWrapper + from django.db.backends.postgresql_psycopg2.base import CursorWrapper as DjangoCursorWrapper + from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation as BaseDatabaseCreation POOL_SETTINGS = 'DATABASE_POOL_ARGS' @@ -93,14 +100,14 @@ def executemany(self, query, args): raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2] -class DatabaseCreation(Psycopg2DatabaseCreation): +class DatabaseCreation(BaseDatabaseCreation): def destroy_test_db(self, *args, **kw): """Ensure connection pool is disposed before trying to drop database.""" self.connection._dispose() super(DatabaseCreation, self).destroy_test_db(*args, **kw) -class DatabaseWrapper(Psycopg2DatabaseWrapper): +class DatabaseWrapper(BaseDatabaseWrapper): """SQLAlchemy FTW.""" def __init__(self, *args, **kwargs):