mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 11:33:59 +03:00
Added URLField and SlugField.
Fixed test_modelserializer_max_length_exceeded
This commit is contained in:
parent
f385b72d80
commit
1a436dd6d9
|
@ -700,6 +700,23 @@ class CharField(WritableField):
|
||||||
return smart_unicode(value)
|
return smart_unicode(value)
|
||||||
|
|
||||||
|
|
||||||
|
class URLField(CharField):
|
||||||
|
type_name = 'URLField'
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
kwargs['max_length'] = kwargs.get('max_length', 200)
|
||||||
|
kwargs['validators'] = [validators.URLValidator()]
|
||||||
|
super(URLField, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class SlugField(CharField):
|
||||||
|
type_name = 'SlugField'
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
kwargs['max_length'] = kwargs.get('max_length', 50)
|
||||||
|
super(SlugField, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ChoiceField(WritableField):
|
class ChoiceField(WritableField):
|
||||||
type_name = 'ChoiceField'
|
type_name = 'ChoiceField'
|
||||||
widget = widgets.Select
|
widget = widgets.Select
|
||||||
|
|
|
@ -441,6 +441,8 @@ class ModelSerializer(Serializer):
|
||||||
models.DateField: DateField,
|
models.DateField: DateField,
|
||||||
models.EmailField: EmailField,
|
models.EmailField: EmailField,
|
||||||
models.CharField: CharField,
|
models.CharField: CharField,
|
||||||
|
models.URLField: URLField,
|
||||||
|
models.SlugField: SlugField,
|
||||||
models.TextField: CharField,
|
models.TextField: CharField,
|
||||||
models.CommaSeparatedIntegerField: CharField,
|
models.CommaSeparatedIntegerField: CharField,
|
||||||
models.BooleanField: BooleanField,
|
models.BooleanField: BooleanField,
|
||||||
|
|
|
@ -245,7 +245,7 @@ class ValidationTests(TestCase):
|
||||||
}
|
}
|
||||||
serializer = ActionItemSerializer(data=data)
|
serializer = ActionItemSerializer(data=data)
|
||||||
self.assertEquals(serializer.is_valid(), False)
|
self.assertEquals(serializer.is_valid(), False)
|
||||||
self.assertEquals(serializer.errors, {'content': [u'Ensure this value has at most 200 characters (it has 201).']})
|
self.assertEquals(serializer.errors, {'title': [u'Ensure this value has at most 200 characters (it has 201).']})
|
||||||
|
|
||||||
|
|
||||||
class MetadataTests(TestCase):
|
class MetadataTests(TestCase):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user