Override destroy to check for associations before deletion
(self, request, *args, **kwargs)
| 713 | }) |
| 714 | |
| 715 | def destroy(self, request, *args, **kwargs): |
| 716 | """Override destroy to check for associations before deletion""" |
| 717 | instance = self.get_object() |
| 718 | |
| 719 | # Check if group has associated channels |
| 720 | if instance.channels.exists(): |
| 721 | return Response( |
| 722 | {"error": "Cannot delete group with associated channels"}, |
| 723 | status=status.HTTP_400_BAD_REQUEST |
| 724 | ) |
| 725 | |
| 726 | # Check if group has M3U account associations |
| 727 | if hasattr(instance, 'm3u_account') and instance.m3u_account.exists(): |
| 728 | return Response( |
| 729 | {"error": "Cannot delete group with M3U account associations"}, |
| 730 | status=status.HTTP_400_BAD_REQUEST |
| 731 | ) |
| 732 | |
| 733 | return super().destroy(request, *args, **kwargs) |
| 734 | |
| 735 | |
| 736 | # ───────────────────────────────────────────────────────── |