@@ -136,7 +136,10 @@ def patch(self, request, item_id):
136136
137137 if updated_data_exists :
138138 item .save (update_fields = fields_to_save )
139- cache .incr ('item_list_version' )
139+ if cache .get ('item_list_version' ) is None :
140+ cache .set ('item_list_version' , 1 )
141+ else :
142+ cache .incr ('item_list_version' )
140143
141144 return JsonResponse ({'MESSAGE' : 'UPDATED' }, status = 200 )
142145
@@ -151,22 +154,24 @@ def patch(self, request, item_id):
151154 except KeyError :
152155 return JsonResponse ({'ERROR' : 'KEY_ERROR' }, status = 400 )
153156
154- @authorization
155157 def delete (self , request , item_id ):
156158 try :
157159 item = Item .objects .get (id = item_id )
160+ item .delete ()
158161
159- if item :
160- item .delete ()
162+ try :
163+ cache .incr ('item_list_version' )
164+ except ValueError :
165+ cache .set ('item_list_version' , 1 )
161166
162- return JsonResponse ({'MESSAGE' : 'DELETED' }, status = 200 )
167+ return JsonResponse ({'MESSAGE' : 'DELETED' }, status = 200 )
163168
164- else :
165- return JsonResponse ({'ERROR' : 'ITEM_DOES_NOT_EXIST' }, status = 400 )
169+ except Item . DoesNotExist :
170+ return JsonResponse ({'ERROR' : 'ITEM_DOES_NOT_EXIST' }, status = 404 )
166171
167172 except ValidationError as e :
168173 return JsonResponse ({'ERROR' : e .message }, status = 400 )
169-
174+
170175 except KeyError :
171176 return JsonResponse ({'ERROR' : 'KEY_ERROR' }, status = 400 )
172177
0 commit comments