summaryrefslogtreecommitdiff
path: root/ishtar_common/views_item.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/views_item.py')
-rw-r--r--ishtar_common/views_item.py28
1 files changed, 27 insertions, 1 deletions
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")