Skip to content

Commit c50f38c

Browse files
committed
fix spatial index creation
1 parent 37ffeb4 commit c50f38c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

django_mongodb_backend/gis/schema.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44

55
class GISSchemaEditor:
6-
def _field_should_be_indexed(self, model, field):
7-
if getattr(field, "spatial_index", False):
8-
return True
9-
return super()._field_should_be_indexed(model, field)
6+
def _create_model_indexes(self, model, column_prefix="", parent_model=None):
7+
super()._create_model_indexes(model, column_prefix, parent_model)
8+
for field in model._meta.local_fields:
9+
if getattr(field, "spatial_index", False):
10+
self._add_spatial_index(parent_model or model, field, column_prefix)
1011

11-
def _add_field_index(self, model, field, *, column_prefix=""):
12+
def add_field(self, model, field):
13+
super().add_field(model, field)
1214
if getattr(field, "spatial_index", False):
13-
self._add_spatial_index(model, field, column_prefix)
14-
else:
15-
super()._add_field_index(model, field, column_prefix=column_prefix)
15+
self._add_spatial_index(model, field)
1616

1717
def _alter_field(
1818
self,

0 commit comments

Comments
 (0)