diff --git a/backend/product/serializers.py b/backend/product/serializers.py index b195885..350bb15 100644 --- a/backend/product/serializers.py +++ b/backend/product/serializers.py @@ -116,7 +116,10 @@ class DynamicProductSerializer(serializers.ModelSerializer): } def get_variants(self, obj): - return ProductVariantSerialzier(instance=obj.variants.all(), many=True, context=self.context).data + varients = obj.variants.all() + colors = set(varient.color for varient in varients) + response = {color: ProductVariantSerialzier(instance=varients.filter(color=color), many=True, context=self.context).data for color in colors} + return response # def get_variants_colors(self, obj): # varients = obj.variants.all() @@ -149,3 +152,4 @@ class CommentSerializer(serializers.ModelSerializer): exclude = ('review_status', ) read_only_fields = ('review_status', 'product', 'user') + \ No newline at end of file