Merge branch 'feature/collection-object-types' into 'develop'
Feature/collection object types See merge request gm/gm-backend!184
This commit is contained in:
commit
5afd0884ee
|
|
@ -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, 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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user