From 0420fafabf8c8612c5943cc8b921bb0fee022ab7 Mon Sep 17 00:00:00 2001 From: dormantman Date: Fri, 20 Dec 2019 16:52:25 +0300 Subject: [PATCH] Added types to collection objects --- apps/collection/models.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/collection/models.py b/apps/collection/models.py index 90837cd7..61e59788 100644 --- a/apps/collection/models.py +++ b/apps/collection/models.py @@ -118,22 +118,23 @@ class Collection(ProjectBaseMixin, CollectionDateMixin, instances = getattr(self, f'{related_object}') if instances.exists(): for instance in instances.all(): - raw_object = (instance.id, instance.slug) if hasattr(instance, 'slug') else ( - instance.id, None - ) + raw_object = (instance.id, instance.establishment_type.index_name, + instance.slug) if \ + hasattr(instance, 'slug') else (instance.id, None) raw_objects.append(raw_object) # parse slugs related_objects = [] object_names = set() re_pattern = r'[\w]+' - for object_id, raw_name, in raw_objects: + for object_id, object_type, raw_name, in raw_objects: result = re.findall(re_pattern, raw_name) if result: name = ' '.join(result).capitalize() if name not in object_names: related_objects.append({ 'id': object_id, + 'establishment_type': object_type, 'name': name }) object_names.add(name)