From 641d5002207daaae6b6166e7d59eec3f4f7a164d Mon Sep 17 00:00:00 2001 From: skks1212 Date: Mon, 4 Sep 2023 16:58:18 +0530 Subject: [PATCH] made project openai key non retrievable --- ayushma/serializers/project.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ayushma/serializers/project.py b/ayushma/serializers/project.py index 39fb0dd6..f6a32523 100644 --- a/ayushma/serializers/project.py +++ b/ayushma/serializers/project.py @@ -22,11 +22,20 @@ class Meta: class ProjectUpdateSerializer(serializers.ModelSerializer): + key_set = serializers.SerializerMethodField() + class Meta: model = Project - fields = ProjectSerializer.Meta.fields + ("prompt", "open_ai_key") + fields = ProjectSerializer.Meta.fields + ("prompt", "open_ai_key", "key_set") + extra_kwargs = { + "open_ai_key": {"write_only": True}, + } + read_only_fields = ("key_set",) def update(self, instance, validated_data): if validated_data.get("is_default", True): Project.objects.all().update(is_default=False) return super().update(instance, validated_data) + + def get_key_set(self, obj): + return obj.open_ai_key is not None