Basically, I have a FileField and, on creation, the other fields are populated by the data extracted from this file.
Some fields of my model have a non-null contraint (a value has to be extracted from the file for those fields).
I'm using a ModelSerializer
and drf fields to add allow_null
to the fields (null=False
in my model) as I am aware of Order of Serializer Validation in Django REST Framework.
The problem is that I want them to be readonly (I just want a form with a file input, remember ?) and according to the drf documentation : Read-only fields are included in the API output, but should not be included in the input during create or update operations.
Because of that I sometimes have to put random values in those fields just to pass the validation phase even if those fields will be populated by the correct values (extracted from the file) afterwards.
How can I ignore the non-null constraint from my model and make my fields readonly in my serializer (not changing my model) ?