From 8a592f6214232f5067f059f2719ef98a7863af24 Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Tue, 7 Oct 2025 12:50:27 +0500 Subject: [PATCH] add error handling for product crearte --- core/apps/products/serializers/product.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/apps/products/serializers/product.py b/core/apps/products/serializers/product.py index 420322b..12edb93 100644 --- a/core/apps/products/serializers/product.py +++ b/core/apps/products/serializers/product.py @@ -30,6 +30,8 @@ class ProductSerializer(serializers.Serializer): sub_folder_id = serializers.UUIDField(required=False) def validate(self, data): + if Product.objects.filter(name=data['name']).exists(): + raise serializers.ValidationError("Product with this name already exists") folder = Folder.objects.filter(id=data.get('folder_id')).first() unity = Unity.objects.filter(id=data.get('unity_id')).first() if not folder: