diff --git a/backend/core/views.py b/backend/core/views.py index 0393f14d4..13e07a6f1 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -382,6 +382,18 @@ class AssetViewSet(BaseModelViewSet): ] search_fields = ["name", "description", "business_value"] + def _perform_write(self, serializer): + type = serializer.validated_data.get("type") + if type == Asset.Type.PRIMARY: + serializer.validated_data["parent_assets"] = [] + serializer.save() + + def perform_create(self, serializer): + return self._perform_write(serializer) + + def perform_update(self, serializer): + return self._perform_write(serializer) + @action(detail=False, name="Get type choices") def type(self, request): return Response(dict(Asset.Type.choices)) diff --git a/frontend/src/lib/components/Forms/ModelForm/AssetForm.svelte b/frontend/src/lib/components/Forms/ModelForm/AssetForm.svelte index 4e924356b..95c2bf0f8 100644 --- a/frontend/src/lib/components/Forms/ModelForm/AssetForm.svelte +++ b/frontend/src/lib/components/Forms/ModelForm/AssetForm.svelte @@ -106,6 +106,7 @@ />