1👍
✅
You almost did it right with serializer, you just forgot to put it inside error_messages
from django.utils.translation import ugettext_lazy as _
class PositionSerializer(serializers.ModelSerializer):
class Meta:
model = MyModel
fields = ('id', 'name', 'description')
extra_kwargs = {"name": {"error_messages": {"blank": _("Customized message goes here")}}}
Also you can try setting this message in model. Using blank
class MyModel(models.Model):
name = models.CharField(..., error_messages={'blank': _("Customized message goes here")})
0👍
You can go as in your example 1, but instead of “required” use keyword “blank”:
def __init__(self, *args, **kwargs):
super(PositionSerializer, self).__init__(*args, **kwargs)
self.fields['name'].error_messages['blank'] = 'My custom required msg'
- Django customizing user view?
- Nginx reverse proxy for nginx+gunicorn+django server
- Redirect to different App view directory from urls.py
- Django Modelform Redirect to form-submitted content
Source:stackexchange.com