mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 01:26:53 +03:00
Changed default widget for TextField with choices to select (#6892)
This commit is contained in:
parent
dff9759555
commit
4d9f9eb192
|
@ -91,7 +91,8 @@ def get_field_kwargs(field_name, model_field):
|
|||
if isinstance(model_field, models.SlugField):
|
||||
kwargs['allow_unicode'] = model_field.allow_unicode
|
||||
|
||||
if isinstance(model_field, models.TextField) or (postgres_fields and isinstance(model_field, postgres_fields.JSONField)):
|
||||
if isinstance(model_field, models.TextField) and not model_field.choices or \
|
||||
(postgres_fields and isinstance(model_field, postgres_fields.JSONField)):
|
||||
kwargs['style'] = {'base_template': 'textarea.html'}
|
||||
|
||||
if isinstance(model_field, models.AutoField) or not model_field.editable:
|
||||
|
|
|
@ -89,6 +89,7 @@ class FieldOptionsModel(models.Model):
|
|||
default_field = models.IntegerField(default=0)
|
||||
descriptive_field = models.IntegerField(help_text='Some help text', verbose_name='A label')
|
||||
choices_field = models.CharField(max_length=100, choices=COLOR_CHOICES)
|
||||
text_choices_field = models.TextField(choices=COLOR_CHOICES)
|
||||
|
||||
|
||||
class ChoicesModel(models.Model):
|
||||
|
@ -211,6 +212,7 @@ class TestRegularFieldMappings(TestCase):
|
|||
default_field = IntegerField(required=False)
|
||||
descriptive_field = IntegerField(help_text='Some help text', label='A label')
|
||||
choices_field = ChoiceField(choices=(('red', 'Red'), ('blue', 'Blue'), ('green', 'Green')))
|
||||
text_choices_field = ChoiceField(choices=(('red', 'Red'), ('blue', 'Blue'), ('green', 'Green')))
|
||||
""")
|
||||
self.assertEqual(repr(TestSerializer()), expected)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user