From fa8a623ef577c44eea86984e14ce4f34f1a36ce7 Mon Sep 17 00:00:00 2001 From: Lloyd Dakin Date: Tue, 27 Feb 2024 15:28:06 -0800 Subject: [PATCH] update overwrite to remove duplicate data --- datalab/datalab_session/serializers.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/datalab/datalab_session/serializers.py b/datalab/datalab_session/serializers.py index eca3a00..f1b1b37 100644 --- a/datalab/datalab_session/serializers.py +++ b/datalab/datalab_session/serializers.py @@ -27,3 +27,16 @@ class DataSessionSerializer(serializers.ModelSerializer): class Meta: model = DataSession fields = '__all__' + + def update(self, instance, validated_data): + input_data = validated_data.get('input_data', []) + + # Check for duplicates + existing_input_data = instance.input_data + new_input_data = [] + for item in input_data: + if item not in existing_input_data: + new_input_data.append(item) + + validated_data['input_data'] = existing_input_data + new_input_data + return super().update(instance, validated_data)