Skip to content
Advertisement

How to give the data to serializer with JSONField

I have model and serializer with JSONField

JavaScript

Then,I want to set the data to serializer class,

However some how serializer.is_valid() faild.

I have tested two pettern data1 data2

JavaScript

What data should I give to this serializer?

And is there any method to debug is_valid()?

Advertisement

Answer

You are giving the data in right way, but as you are updating partially, you need to pass one more parameter:

JavaScript

To debug the is_valid method, you can either throw exceptions from it like .is_valid(raise_exception=True); or in your code, print serializer.errors in else block to print the exact errors. More information on validation can be found in documentation.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement