|
25 | 25 |
|
26 | 26 | from rest_framework import serializers |
27 | 27 | from rest_framework.compat import postgres_fields |
| 28 | +from rest_framework.fields import ChoiceField |
28 | 29 |
|
29 | 30 | from .models import NestedForeignKeySource |
30 | 31 |
|
@@ -95,6 +96,7 @@ class FieldOptionsModel(models.Model): |
95 | 96 |
|
96 | 97 | class ChoicesModel(models.Model): |
97 | 98 | choices_field_with_nonstandard_args = models.DecimalField(max_digits=3, decimal_places=1, choices=DECIMAL_CHOICES, verbose_name='A label') |
| 99 | + non_editable_choice_field = models.CharField(choices=COLOR_CHOICES, default=COLOR_CHOICES[0][0], editable=False, max_length=5) |
98 | 100 |
|
99 | 101 |
|
100 | 102 | class Issue3674ParentModel(models.Model): |
@@ -360,7 +362,23 @@ class Meta: |
360 | 362 | model = ChoicesModel |
361 | 363 | fields = '__all__' |
362 | 364 |
|
363 | | - ExampleSerializer() |
| 365 | + serializer = ExampleSerializer() |
| 366 | + choices_field_with_nonstandard_args = serializer.get_fields()['choices_field_with_nonstandard_args'] |
| 367 | + assert isinstance(choices_field_with_nonstandard_args, ChoiceField) |
| 368 | + assert choices_field_with_nonstandard_args.choices |
| 369 | + assert choices_field_with_nonstandard_args.read_only is False |
| 370 | + |
| 371 | + def test_non_editable_choice_field(self): |
| 372 | + class ExampleSerializer(serializers.ModelSerializer): |
| 373 | + class Meta: |
| 374 | + model = ChoicesModel |
| 375 | + fields = '__all__' |
| 376 | + |
| 377 | + serializer = ExampleSerializer() |
| 378 | + non_editable_choice_field = serializer.get_fields()['non_editable_choice_field'] |
| 379 | + assert isinstance(non_editable_choice_field, ChoiceField) |
| 380 | + assert non_editable_choice_field.read_only is True |
| 381 | + assert non_editable_choice_field.choices |
364 | 382 |
|
365 | 383 |
|
366 | 384 | class TestDurationFieldMapping(TestCase): |
|
0 commit comments