'Returns a dictionary with keys that are the PostgreSQL object
identification integers for the PostGIS geometry and/or
geography types (if supported).'

def get_postgis_types(self):

    cursor = self.connection.cursor()
    oid_sql = 'SELECT    "oid"    FROM    "pg_type"    WHERE    "typname"    =    %s'
    try:
        cursor.execute(oid_sql, ('geometry',))
        GEOM_TYPE = cursor.fetchone()[0]
        postgis_types = {GEOM_TYPE: 'GeometryField'}
        if self.connection.ops.geography:
            cursor.execute(oid_sql, ('geography',))
            GEOG_TYPE = cursor.fetchone()[0]
            postgis_types[GEOG_TYPE] = ('GeometryField', {'geography': True})
    finally:
        cursor.close()
    return postgis_types
