| 1823 | ) |
| 1824 | @action(detail=False, methods=["post"], url_path="assign") |
| 1825 | def assign(self, request): |
| 1826 | with transaction.atomic(): |
| 1827 | channel_ids = request.data.get("channel_ids", []) |
| 1828 | # Ensure starting_number is processed as a float |
| 1829 | try: |
| 1830 | channel_num = float(request.data.get("starting_number", 1)) |
| 1831 | except (ValueError, TypeError): |
| 1832 | channel_num = 1.0 |
| 1833 | |
| 1834 | for channel_id in channel_ids: |
| 1835 | Channel.objects.filter(id=channel_id).update(channel_number=channel_num) |
| 1836 | channel_num = channel_num + 1 |
| 1837 | |
| 1838 | return Response( |
| 1839 | {"message": "Channels have been auto-assigned!"}, status=status.HTTP_200_OK |
| 1840 | ) |
| 1841 | |
| 1842 | @extend_schema( |
| 1843 | methods=["POST"], |