B
B
bubaley2020-05-02 16:27:00
Django
bubaley, 2020-05-02 16:27:00

How in django DRF ModelSerializer to check for additional fields that are not in the model?

hello there is a model

class ItemSerializer(serializers.ModelSerializer):
    test_field = serializers.CharField(max_length=100, required=True)

    class Meta:
        model = models.Item
        fields = ('id', 'name', 'test_field')


But in this code, it expects the test_field to be in the model. How to make sure that there is a check, but this field does not have to be in the model?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alternativshik, 2020-05-02
@alternativshik

I suspect that it does not swear during validation, but at the time of saving.
And there is nothing to save, since there is no such field. So you need to change the save.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question