Skip to content

Commit

Permalink
Merge pull request #122 from snuhcs-course/fix/delete-weight
Browse files Browse the repository at this point in the history
🐛 상징 삭제 시 db에서 weight row 따라서 삭제해주도록 수정
  • Loading branch information
JH747 authored Dec 10, 2023
2 parents b697580 + 78a3f66 commit b6c5af1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions backend/weight_table/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ def post(self, request):
serializer.is_valid(raise_exception=True)
serializer.save()

# Delete weight rows if user deleted corresponding symbols
weight_symbols = WeightTable.objects.filter(user=user).values('symbol_id')
weight_to_delete = [item['symbol_id'] for item in weight_symbols]

try:
for item in serializer.validated_data:
weight_to_delete.remove(item.get('symbol_id'))
except ValueError:
pass

for id in weight_to_delete:
WeightTable.objects.get(symbol_id=id, user=user).delete()

return Response(status=status.HTTP_200_OK)

def get(self, request):
Expand Down

0 comments on commit b6c5af1

Please sign in to comment.