Почему я получаю один объект массива вместо всех значений массива в Django rest framework?

Я использую Django rest framework для API и pandas для анализа файла excel. Но моя модель Django принимает только последнюю строку файла excel и возвращает ее. Я хочу, чтобы все строки были отправлены и возвращены. Вот мой код.

models.py

class BusinessImpact(models.Model, ModelWithCreateFromDict):
    client = models.ForeignKey(
        accounts_models.Client, on_delete=models.CASCADE)
    business_process = models.ForeignKey(
        BusinessProcess, on_delete=models.CASCADE)
    hierarchy = models.CharField(max_length=255)
    business_assets = models.CharField(max_length=255)
    asset_name = models.CharField(max_length=255)
    vendors = models.CharField(max_length=255)
    product = models.CharField(max_length=255)
    version = models.CharField(max_length=10)
    cpe = models.CharField(max_length=255)
    asset_type = models.CharField(max_length=10)
    asset_categorization = models.CharField(max_length=255)
    asset_risk = models.CharField(max_length=50)
    _regulations = models.TextField(blank=True)
    _geolocation = models.TextField(blank=True)

    def __str__(self) -> str:
        return self.hierarchy + " - " + self.business_assets

    @property
    def regulations(self) -> List[str]:
        return self._regulations.split(",")

    @property
    def geolocation(self) -> List[str]:
        return self._geolocation.split(",")

    excel_titles = {
        "hierarchy": "Hierarchy",
        "business_assets": "Business Assets",
        "asset_name": "Asset Name",
        "vendors": "Vendors",
        "product": "Product",
        "version": "Version",
        "cpe": "CPE",
        "asset_type": "Asset Type",
        "asset_categorization": "Asset Categorization",
        "asset_risk": "Asset Risk",
        "_regulations": "Regulations",
        "_geolocation": "GeoLocation",
    }

    important_fields = ["hierarchy", "business_assets", "asset_name"]

views.py

class UploadBusinessImpactExcelByClientAdmin(APIView, ExcelHandlingView):

    def post(self, request):
        self.can_model_handle_ExcelHandlingView(models.BusinessImpact)

        serializer = serializers.ExcelFileAndBusinessProcessUploader(
            data=request.data)
        if serializer.is_valid():
            data = serializer.validated_data
            file = data.get("file")
            client = request.user.client
            business_process_id = data.get("business_process")

            try:
                business_process = get_business_process_by_client(
                    client, business_process_id
                )
            except (
                models.BusinessProcess.DoesNotExist,
                accountModels.Client.DoesNotExist,
            ) as e:
                return Response(
                    "business process or client does not exist",
                    status=status.HTTP_404_NOT_FOUND,
                )

            if (
                file.content_type
                == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            ):
                # self.delete_every_recore_on_that_model(models.BusinessImpact)
                self.delete_every_record_that_match_criteria(
                    models.BusinessImpact,
                    {"client": client, "business_process": business_process},
                )
                excel_file = pd.read_excel(file))
                data = pd.DataFrame(
                    excel_file,
                    columns=self.get_excel_fields(
                        models.BusinessImpact.excel_titles),
                )

                for _, row in data.iterrows():
                    self.create_model_object(
                        models.BusinessImpact,
                        row,
                        {"client": client.id, "business_process": business_process.id},
                    )

                return Response("Successfully Loaded data from excel.")

            else:
                return Response(
                    {"file": ["File type must be excel with .xlxs extension."]},
                    status=status.HTTP_400_BAD_REQUEST,
                )

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Мой API работает хорошо, но он не читает все строки, вместо этого он читает последнюю строку и возвращает ее. Вот консольный журнал того, что я получаю от API.

0:
asset_categorization: "Sensitive"
asset_name: "Primary Data Center"
asset_risk: "High"
asset_type: "I"
business_assets: "Infrastructure"
business_process: {id: 1, name: 'Credit Management'}
client: 1
cpe: "cpe:2.3:a:oracle:peoplesoft_enterprise:8.22.14"
hierarchy: "L7 / DATA CENTER"
id: 1170
product: "gbfg"
vendors: "ghg"
version: "fgf"
_geolocation: "cvb v"
_regulations: "gvbv"
[[Prototype]]: Object

Что я могу сделать, чтобы прочитать все строки?

Спасибо

Вернуться на верх