summaryrefslogtreecommitdiff
path: root/ishtar_common/models_common.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-11-04 17:48:38 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:23:19 +0100
commitb8f767ae2524dd3595afadbcb323a974efdb453e (patch)
tree4d98f8e5f5fdf2e826b89cf85ec4450c382ad471 /ishtar_common/models_common.py
parent0ec7dc7f640b315cbf4c3e247e6a8a3cda6581cd (diff)
downloadIshtar-b8f767ae2524dd3595afadbcb323a974efdb453e.tar.bz2
Ishtar-b8f767ae2524dd3595afadbcb323a974efdb453e.zip
Geodata: display first item associated as a name when no name is provided
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r--ishtar_common/models_common.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index 779af635b..dc35cade2 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -2210,6 +2210,16 @@ class GeoVectorData(Imported, OwnPerms):
def __str__(self):
name = self.name
+ if not name or name == "-":
+ for related_model in self.RELATED_MODELS:
+ q = getattr(self, related_model)
+ cached_label_key = "cached_label"
+ if getattr(q.model, "GEO_LABEL", None):
+ cached_label_key = q.model.GEO_LABEL
+ if q.count(): # arbitrary return the first item
+ name = str(q.values_list(cached_label_key, flat=True).all()[0])
+ break
+
if self.data_type:
name += f" ({str(self.data_type).lower()})"
return name