Files
Rasadyar_RSI/app/scripts.py
2026-01-18 11:29:19 +03:30

25 lines
1.0 KiB
Python

from rest_framework import status
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from app.models import PoultryHatching, Poultry
from django.db import transaction
from django.views.decorators.csrf import csrf_exempt
from rest_framework.decorators import api_view, permission_classes
@api_view(['POST'])
@permission_classes([AllowAny])
@csrf_exempt
def update_poultry_city_province(request):
hatchings = PoultryHatching.objects.select_related('poultry').only('poultry', 'LocationNameCity',
'LocationNameProvince').filter(
poultry__isnull=False).order_by('id')
for hatching in hatchings:
hatching.poultry.LocationNameProvince = hatching.LocationNameProvince
hatching.poultry.LocationNameCity = hatching.LocationNameCity
hatching.poultry.save()
print(hatching.id)
return Response({'message': 'done'}, status=status.HTTP_200_OK)
# return Response({'message': len(hatchings)}, status=status.HTTP_200_OK)