summaryrefslogtreecommitdiff
path: root/ishtar_common/models_common.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r--ishtar_common/models_common.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index dcb4f05a3..96f0f5d86 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -2957,6 +2957,24 @@ class GeoVectorData(Imported, OwnPerms):
self.save()
return True
+ def update_import_key(self):
+ if self.import_key or not self.data_type:
+ return
+ # by default set import key to data type
+ base_import_key = import_key = self.data_type.txt_idx
+ base_q = GeoVectorData.objects.filter(
+ source_content_type_id=self.source_content_type_id,
+ source_id=self.source_id
+ )
+ idx = 0
+ q = base_q.filter(import_key=import_key)
+ while q.count():
+ idx += 1
+ import_key = f"{base_import_key}-{idx}"
+ q = base_q.filter(import_key=import_key)
+ GeoVectorData.objects.filter(pk=self.id).update(import_key=import_key)
+ return True
+
@classmethod
def migrate_srid(cls, new_srid):
fields = (
@@ -2976,7 +2994,15 @@ class GeoVectorData(Imported, OwnPerms):
item.save()
-post_save.connect(post_save_geodata, sender=GeoVectorData)
+def post_save_geovectordata(sender, **kwargs):
+ geovectordata = kwargs["instance"]
+ if not geovectordata.pk:
+ return
+ geovectordata.update_import_key()
+ post_save_geodata(sender, **kwargs)
+
+
+post_save.connect(post_save_geovectordata, sender=GeoVectorData)
def geodata_attached_post_add(model, instance, pk_set):