Unexpected keyword arguments

I have gone through many posts on SO and other places but I am unable to find a solution to the same problem.

I am getting the following error

TypeError: Basetable() got unexpected keyword arguments: 'CashCashEquivalentsRestrictedCashAndRestrictedCashEquivalents'

I have the following JSON Data

    jsonToUse = {
        "CompanyId": "320193",
        "CashCashEquivalentsRestrictedCashAndRestrictedCashEquivalents": [
            {
                "decimals": "-6",
                "unitRef": "usd",
                "value": "39789000000"
            },
            {
                "decimals": "-6",
                "unitRef": "usd",
                "value": "50224000000"
            },
            {
                "decimals": "-6",
                "unitRef": "usd",
                "value": "25913000000"
            },
            {
                "decimals": "-6",
                "unitRef": "usd",
                "value": "35929000000"
            }
        ]
    }

Model:

class Basetable(models.Model):
    basetable_id = models.AutoField(primary_key=True)
    CompanyId = models.IntegerField()


class Cashcashequivalentsrestrictedcashandrestrictedcashequivalents(models.Model):
    cashcashequivalentsrestrictedcashandrestrictedcashequivalents_id = models.AutoField(
        primary_key=True)
    unitRef = models.CharField(max_length=100)
    value = models.CharField(max_length=100)
    decimals = models.IntegerField()
    basetable_id = models.ForeignKey(Basetable, on_delete=models.CASCADE)

Serializer:

class CashCashEquivalentsRestrictedCashAndRestrictedCashEquivalentsSerializer(serializers.ModelSerializer):

    class Meta:
        model = Cashcashequivalentsrestrictedcashandrestrictedcashequivalents
        fields = ['decimals', 'unitRef', 'value']


class CashFlowSerializer(serializers.ModelSerializer):
    CashCashEquivalentsRestrictedCashAndRestrictedCashEquivalents = CashCashEquivalentsRestrictedCashAndRestrictedCashEquivalentsSerializer(
        many=True)

    class Meta:
        model = Basetable
        fields = "__all__"

View:

.....#TRIMMED GET SYNTAX.....
check = CashFlowSerializer(data=jsonToUse)
if (check.is_valid(raise_exception=True)):
    print("ready to send to db")
    check.save()
return JsonResponse(jsonToUse, safe=False)

I want to save the data in the database for the provided JSON

Back to Top