How to pre-process data received from front-end before saving to database using class views?

Hello there !

First post, please guide me if I’m doing anything wrong.

The core question: I am receiving unprocessed financial data from front end, thus integer fields can have strings in it and so on.

As I read the documentation, I felt a little loss regarding how to tackle this issue with using class views.

Let’s consider that I receive the following JSON (single row), what is the best way to tackle it?
{‘pkid’: ‘1’, ‘user’: ‘Bob’, ‘Date’: ‘20221028’, ‘Account’: ‘411016’, ‘Amount’: ‘00000124.2’}

Basically, I want to save my model as such (using class views) :

from django.conf import settings
from django.db import models

class Fec(models.Model):
    pkid = models.BigAutoField(primary_key=True, editable=False)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    Date= models.DateField(max_length=20)
    Account=  models.IntegerField()
    Amount= models.FloatField()

I made a simple serializer:

from rest_framework import serializers

class FecSerializer(serializers.ModelSerializer):
    user = serializers.PrimaryKeyRelatedField(
    class Meta:
        fields = (
        model = Fec

I am a little lost on how to handle the logic on the serializer part (for class view). Considering that the preprocessing and data tables are quite large in my project, I’m using pandas.

Any input on how to tackle this part well? Am I even going in the right direction?

from django.shortcuts import render
from rest_framework import generics
from django.contrib.auth import get_user_model
from rest_framework import status
from rest_framework.response import Response

import pandas as pd

from .models import Fec
from .serializers import FecSerializer

class FecList(generics.ListCreateAPIView):
    serializer_class = FecSerializer

    def preprocess_data(self, request):
        data =
        df = pd.DataFrame([data])
        df["Date"] = pd.to_datetime(df["Date"], format='%Y%m%d')
        df["Amount"]= df["Amount"].astype(str).str.replace(',','.').str.lstrip('0').astype(float)
        json_df = df.to_json(orient='columns')
        return json_df

    def get_queryset(self):
        user = self.request.user
        queryset = Fec.objects.filter(user=user)
        return queryset

    def perform_create(self, serializer):
    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=self.preprocess_data(request))
        headers = self.get_success_headers(
        return Response(, status=status.HTTP_201_CREATED, headers=headers)

Edit: I understand that the self.get_serializer() needs to receive a dic, I would need to pass the column manually and convert them to json in this part. But it does not feel right.