From b8f767ae2524dd3595afadbcb323a974efdb453e Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 4 Nov 2022 17:48:38 +0100 Subject: Geodata: display first item associated as a name when no name is provided --- ishtar_common/models_common.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ishtar_common/models_common.py') 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 -- cgit v1.2.3