mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 20:10:10 +03:00
Pickup custom message for URLField
This commit is contained in:
parent
e7dd68e8fa
commit
c3fd86d323
|
@ -156,6 +156,9 @@ def get_field_kwargs(field_name, model_field):
|
|||
# URLField does not need to include the URLValidator argument,
|
||||
# as it is explicitly added in.
|
||||
if isinstance(model_field, models.URLField):
|
||||
custom_message = model_field.error_messages.get("invalid", None)
|
||||
if custom_message is not None:
|
||||
kwargs.setdefault('error_messages', {}).update(invalid=custom_message)
|
||||
validator_kwarg = [
|
||||
validator for validator in validator_kwarg
|
||||
if not isinstance(validator, validators.URLValidator)
|
||||
|
|
|
@ -3,7 +3,7 @@ import datetime
|
|||
import pytest
|
||||
from django.core.validators import (
|
||||
MaxLengthValidator, MaxValueValidator, MinLengthValidator,
|
||||
MinValueValidator, URLValidator
|
||||
MinValueValidator
|
||||
)
|
||||
from django.db import DataError, models
|
||||
from django.test import TestCase
|
||||
|
@ -597,7 +597,9 @@ class ValidatorMessageTests(TestCase):
|
|||
|
||||
def test_url_validator_message_is_copied_from_model(self):
|
||||
class BlogModel(models.Model):
|
||||
url = models.URLField(validators=[URLValidator(message='This URL is not valid.')])
|
||||
url = models.URLField(
|
||||
error_messages={"invalid": "This URL is not valid."}
|
||||
)
|
||||
|
||||
class BlogSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
|
|
Loading…
Reference in New Issue
Block a user