diff options
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 |
commit | 2d99266012a4cb76896c094a786d9aaec74a1f29 (patch) | |
tree | 4d98f8e5f5fdf2e826b89cf85ec4450c382ad471 /ishtar_common/models_common.py | |
parent | 14ef831ec67d44825df52347a091bf93244eb743 (diff) | |
download | Ishtar-2d99266012a4cb76896c094a786d9aaec74a1f29.tar.bz2 Ishtar-2d99266012a4cb76896c094a786d9aaec74a1f29.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.py | 10 |
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 |