From fadce108d361c1b4094420e71b785324c48a3f94 Mon Sep 17 00:00:00 2001
From: Ernesto Rico Schmidt <ernesto@helsinki.at>
Date: Fri, 5 May 2023 11:24:11 -0400
Subject: [PATCH] Clean-up TimeslotSerializer

---
 program/serializers.py | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/program/serializers.py b/program/serializers.py
index 2da7a153..40679801 100644
--- a/program/serializers.py
+++ b/program/serializers.py
@@ -678,29 +678,28 @@ class ScheduleDryRunResponseSerializer(serializers.Serializer):
 
 
 class TimeSlotSerializer(serializers.ModelSerializer):
-    show = serializers.PrimaryKeyRelatedField(queryset=Show.objects.all())
-    schedule = serializers.PrimaryKeyRelatedField(queryset=Schedule.objects.all())
+    show = serializers.PrimaryKeyRelatedField(queryset=Show.objects.all(), required=False)
+    schedule = serializers.PrimaryKeyRelatedField(queryset=Schedule.objects.all(), required=False)
     repetition_of = serializers.PrimaryKeyRelatedField(
-        queryset=TimeSlot.objects.all(), allow_null=True
+        allow_null=True,
+        queryset=TimeSlot.objects.all(),
+        required=False,
     )
 
     class Meta:
         model = TimeSlot
-        fields = (
+        read_only_fields = (
             "id",
             "end",
-            "memo",
-            "note_id",
-            "playlist_id",
-            "repetition_of",
             "schedule",
             "show",
             "start",
         )
-
-    def create(self, validated_data):
-        """Create and return a new TimeSlot instance, given the validated data."""
-        return TimeSlot.objects.create(**validated_data)
+        fields = (
+            "memo",
+            "playlist_id",
+            "repetition_of",
+        ) + read_only_fields
 
     def update(self, instance, validated_data):
         """Update and return an existing Show instance, given the validated data."""
-- 
GitLab