@@ -240,28 +240,22 @@ class Meta:
240240
241241 def get_image (self , obj : Event ) -> dict :
242242 img = obj .image
243- return {
244- "id" : img .id ,
245- "url" : img .image .url ,
246- "title" : img .title ,
247- "tags" : list (img .tags .values_list ("id" , flat = True ))
248- }
243+ return {'id' : img .id , 'url' : img .image .url , 'title' : img .title , 'tags' : list (img .tags .values_list ('id' , flat = True ))}
249244
250245 def update (self , instance : Event , validated_data : dict [str , Any ]) -> Event :
251- image_id = validated_data .pop (" image_id" , None )
246+ image_id = validated_data .pop (' image_id' , None )
252247 if image_id is not None :
253248 try :
254249 instance .image = Image .objects .get (pk = image_id )
255250 except Image .DoesNotExist as err :
256- raise serializers .ValidationError ({" image_id" : " Invalid image id" }) from err
251+ raise serializers .ValidationError ({' image_id' : ' Invalid image id' }) from err
257252
258253 for attr , value in validated_data .items ():
259254 setattr (instance , attr , value )
260255
261256 instance .save ()
262257 return instance
263258
264-
265259 def validate (self , data : dict ) -> dict :
266260 # Check if all required fields are present for validation
267261 if all (key in data for key in ['start_dt' , 'end_dt' , 'visibility_from_dt' , 'visibility_to_dt' ]):
@@ -285,7 +279,7 @@ def create(self, validated_data: dict) -> Event:
285279 and sets it in the new event. Read/write only fields enable
286280 us to use the same serializer for both reading and writing.
287281 """
288- image_id = validated_data .pop (" image_id" )
282+ image_id = validated_data .pop (' image_id' )
289283 validated_data ['image' ] = Image .objects .get (pk = image_id )
290284 event = Event (** validated_data )
291285 event .save ()
0 commit comments