/django/contrib/gis/db/backends/mysql/creation.py
Python | 18 lines | 15 code | 3 blank | 0 comment | 2 complexity | 40b0a8f864cd0db447d8d59d8fca8105 MD5 | raw file
Possible License(s): BSD-3-Clause
1from django.db.backends.mysql.creation import DatabaseCreation 2 3class MySQLCreation(DatabaseCreation): 4 5 def sql_indexes_for_field(self, model, f, style): 6 from django.contrib.gis.db.models.fields import GeometryField 7 output = super(MySQLCreation, self).sql_indexes_for_field(model, f, style) 8 9 if isinstance(f, GeometryField) and f.spatial_index: 10 qn = self.connection.ops.quote_name 11 db_table = model._meta.db_table 12 idx_name = '%s_%s_id' % (db_table, f.column) 13 output.append(style.SQL_KEYWORD('CREATE SPATIAL INDEX ') + 14 style.SQL_TABLE(qn(idx_name)) + 15 style.SQL_KEYWORD(' ON ') + 16 style.SQL_TABLE(qn(db_table)) + '(' + 17 style.SQL_FIELD(qn(f.column)) + ');') 18 return output