File: creation.py

package info (click to toggle)
python-django 1.2.3-3%2Bsqueeze15
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 29,720 kB
  • ctags: 21,538
  • sloc: python: 101,631; xml: 574; makefile: 149; sh: 121; sql: 7
file content (18 lines) | stat: -rw-r--r-- 855 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from django.db.backends.mysql.creation import DatabaseCreation

class MySQLCreation(DatabaseCreation):

    def sql_indexes_for_field(self, model, f, style):
        from django.contrib.gis.db.models.fields import GeometryField
        output = super(MySQLCreation, self).sql_indexes_for_field(model, f, style)

        if isinstance(f, GeometryField) and f.spatial_index:
            qn = self.connection.ops.quote_name
            db_table = model._meta.db_table
            idx_name = '%s_%s_id' % (db_table, f.column)
            output.append(style.SQL_KEYWORD('CREATE SPATIAL INDEX ') +
                          style.SQL_TABLE(qn(idx_name)) +
                          style.SQL_KEYWORD(' ON ') +
                          style.SQL_TABLE(qn(db_table)) + '(' +
                          style.SQL_FIELD(qn(f.column)) + ');')
        return output