mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 16:24:18 +03:00
Map TextField max_length to CharField
This commit is contained in:
parent
1b4a41cb80
commit
a1dad503cf
|
@ -123,7 +123,8 @@ def get_field_kwargs(field_name, model_field):
|
|||
# Ensure that max_length is passed explicitly as a keyword arg,
|
||||
# rather than as a validator.
|
||||
max_length = getattr(model_field, 'max_length', None)
|
||||
if max_length is not None and isinstance(model_field, models.CharField):
|
||||
if max_length is not None and (isinstance(model_field, models.CharField) or
|
||||
isinstance(model_field, models.TextField)):
|
||||
kwargs['max_length'] = max_length
|
||||
validator_kwarg = [
|
||||
validator for validator in validator_kwarg
|
||||
|
|
|
@ -63,7 +63,7 @@ class RegularFieldsModel(models.Model):
|
|||
positive_small_integer_field = models.PositiveSmallIntegerField()
|
||||
slug_field = models.SlugField(max_length=100)
|
||||
small_integer_field = models.SmallIntegerField()
|
||||
text_field = models.TextField()
|
||||
text_field = models.TextField(max_length=100)
|
||||
time_field = models.TimeField()
|
||||
url_field = models.URLField(max_length=100)
|
||||
custom_field = CustomField()
|
||||
|
@ -161,11 +161,12 @@ class TestRegularFieldMappings(TestCase):
|
|||
positive_small_integer_field = IntegerField()
|
||||
slug_field = SlugField(max_length=100)
|
||||
small_integer_field = IntegerField()
|
||||
text_field = CharField(style={'base_template': 'textarea.html'})
|
||||
text_field = CharField(max_length=100, style={'base_template': 'textarea.html'})
|
||||
time_field = TimeField()
|
||||
url_field = URLField(max_length=100)
|
||||
custom_field = ModelField(model_field=<tests.test_model_serializer.CustomField: custom_field>)
|
||||
""")
|
||||
|
||||
self.assertEqual(unicode_repr(TestSerializer()), expected)
|
||||
|
||||
def test_field_options(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user