Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23218

How can I modify the serializer.is_valid() method for existing rows on the database so it passes the validation

$
0
0

I am trying to insert a list of objects by using serializer.save() but when I try to insert existing data it throws error and doesn't pass the validation how can I modify the is_valid() method or is there any way of skipping the existing objects and inserting the others inside the method

Saving:

data = sanitizer.to_dict()serializer = serializer_class(data=data, many=True)if serializer.is_valid(raise_exception=True):   serializer.save()

Serializer:

from apps.trades.models import Tradefrom rest_framework import serializersclass TradeSerializer(serializers.ModelSerializer):    class Meta:        model = Trade        fields = ['identifier', 'issue_date', 'maturity_date', 'invested_amount', 'interest_rate']

The validation error:

[{"identifier":["trade with this identifier already exists."]}


Viewing all articles
Browse latest Browse all 23218

Trending Articles