summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_warehouse/models.py2
-rw-r--r--ishtar_common/models.py4
-rw-r--r--ishtar_common/views_item.py28
3 files changed, 30 insertions, 4 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 2a04304b2..b3bf02a6b 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -319,7 +319,7 @@ class Warehouse(
),
"town": SearchAltName(
pgettext_lazy("key for text search", "town"),
- "precise_town__cached_label__iexact",
+ "precise_town_id__cached_label",
),
}
GEO_LABEL = "name"
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 3e5b44d8a..c4beb0bff 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2567,9 +2567,9 @@ class Organization(Address, Merge, OwnPerms, BaseGenderedType, ValueGetter, Main
pgettext_lazy("key for text search", "type"),
"organization_type__label__iexact",
),
- "precise_town": SearchAltName(
+ "precise_town_id": SearchAltName(
pgettext_lazy("key for text search", "precise-town"),
- "precise_town__cached_label__iexact",
+ "precise_town_id__cached_label",
),
}
QA_EDIT = QuickAction(
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index b2b924992..31a96f270 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -1066,7 +1066,33 @@ def _manage_hierarchic_fields(model, dct, and_reqs):
# TODO: improve query with "IN ()"?
continue
- if (
+ if req.endswith("precise_town_id__cached_label"):
+ val = _clean_type_val(dct.pop(req)).strip('"')
+ if val.startswith('"') and val.endswith('"'):
+ val = val[1:-1]
+ vals = [v.replace('"', "") for v in val.split(";")]
+ req = req[:-len("__cached_label")]
+ town_ids = []
+ for val in vals:
+ q = models.Town.objects.filter(cached_label__iexact=val).values_list(
+ "id", flat=True)
+ if not q.count():
+ continue
+ town_id = q.all()[0]
+ town_ids.append(town_id)
+ reqs = Q(**{req: val})
+ for rel_query in ("parents__", "children__"):
+ for idx in range(HIERARCHIC_LEVELS):
+ k = rel_query * (idx + 1) + "pk"
+ q = models.Town.objects.filter(
+ **{k: town_id}).values_list("id", flat=True)
+ if not q.count():
+ break
+ town_ids += list(q.all())
+ main_req = Q(**{req + "__in": town_ids})
+ and_reqs.append(main_req)
+
+ elif (
req.endswith("town__pk")
or req.endswith("towns__pk")
or req.endswith("town__cached_label__iexact")