Answer the question
In order to leave comments, you need to log in
How to add custom field to Django Rest Framework errors?
It is necessary that if there are errors after validation, then the "status=error" field is added.
What method should be overwritten for this?
I use generic Views. (if this information is needed)
Ultimately, you should get something like this:
{
"status:"error",
"data":[
"source": [
"This field may not be blank."
],
"description": [
"This field may not be blank."
]
]
}
Answer the question
In order to leave comments, you need to log in
You can do this by overriding the errors property of the serializer class:
# serializers.py
class MySerializer(serializers.ModelSerializer):
# ...
@property
def errors(self):
origin = super().errors
origin['status'] = 'error'
return origin
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question