Merge branch 'feature/back-office-collections' into 'develop'
Feature/back office collections See merge request gm/gm-backend!180
This commit is contained in:
commit
c456e43f80
|
|
@ -112,19 +112,22 @@ class Collection(ProjectBaseMixin, CollectionDateMixin,
|
|||
@property
|
||||
def related_object_names(self) -> list:
|
||||
"""Return related object names."""
|
||||
raw_object_names = {}
|
||||
for related_object in [(related_object.id, related_object.name) for related_object in self._related_objects]:
|
||||
instances = getattr(self, f'{related_object[1]}')
|
||||
raw_objects = []
|
||||
for related_object in [related_object.name for related_object in self._related_objects]:
|
||||
instances = getattr(self, f'{related_object}')
|
||||
if instances.exists():
|
||||
for instance in instances.all():
|
||||
raw_object_names[related_object[0]] = instance.slug if hasattr(instance, 'slug') else None
|
||||
raw_object = (instance.id, 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 in raw_object_names:
|
||||
result = re.findall(re_pattern, raw_object_names[object_id])
|
||||
for object_id, raw_name, in raw_objects:
|
||||
result = re.findall(re_pattern, raw_name)
|
||||
if result:
|
||||
name = ' '.join(result).capitalize()
|
||||
if name not in object_names:
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class CollectionBackOfficeSerializer(CollectionBaseSerializer):
|
|||
source='get_collection_type_display', read_only=True)
|
||||
country = CountrySimpleSerializer(read_only=True)
|
||||
count_related_objects = serializers.IntegerField(read_only=True)
|
||||
related_object_names = serializers.JSONField(read_only=True)
|
||||
related_object_names = serializers.ListField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = models.Collection
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user