Skip to content

Commit

Permalink
Update analysis serializer and add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed Dec 17, 2024
1 parent 3713b87 commit c764d68
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion apps/analysis/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def update(self, instance, validated_data):


class AnalysisCloneGqlSerializer(serializers.Serializer):
analysis_id = serializers.PrimaryKeyRelatedField(queryset=Analysis.objects.all(), required=True)
analysis_id = IntegerIDField()
title = serializers.CharField(required=True, write_only=True)
start_date = serializers.DateField(write_only=True, required=False, allow_null=True)
end_date = serializers.DateField(required=True, write_only=True)
Expand All @@ -494,6 +494,15 @@ def validate(self, data):
)
return data

def validate_analysis_id(self, analysis_id):
analysis = Analysis.objects.filter(
project=self.context['request'].active_project,
pk=analysis_id
).first()
if analysis is None:
raise serializers.ValidationError("Analysis does not exists")
return analysis

def create(self, validated_data):
title = validated_data['title']
end_date = validated_data['end_date']
Expand Down

0 comments on commit c764d68

Please sign in to comment.