Added types to collection objects

This commit is contained in:
dormantman 2019-12-20 16:52:25 +03:00
parent 8e20424b78
commit 0420fafabf

View File

@ -118,22 +118,23 @@ class Collection(ProjectBaseMixin, CollectionDateMixin,
instances = getattr(self, f'{related_object}') instances = getattr(self, f'{related_object}')
if instances.exists(): if instances.exists():
for instance in instances.all(): for instance in instances.all():
raw_object = (instance.id, instance.slug) if hasattr(instance, 'slug') else ( raw_object = (instance.id, instance.establishment_type.index_name,
instance.id, None instance.slug) if \
) hasattr(instance, 'slug') else (instance.id, None)
raw_objects.append(raw_object) raw_objects.append(raw_object)
# parse slugs # parse slugs
related_objects = [] related_objects = []
object_names = set() object_names = set()
re_pattern = r'[\w]+' 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) result = re.findall(re_pattern, raw_name)
if result: if result:
name = ' '.join(result).capitalize() name = ' '.join(result).capitalize()
if name not in object_names: if name not in object_names:
related_objects.append({ related_objects.append({
'id': object_id, 'id': object_id,
'establishment_type': object_type,
'name': name 'name': name
}) })
object_names.add(name) object_names.add(name)