7
7
"""
8
8
from __future__ import unicode_literals
9
9
10
+ import decimal
11
+
10
12
import django
11
13
import pytest
12
14
from django .core .exceptions import ImproperlyConfigured
@@ -70,6 +72,7 @@ def method(self):
70
72
71
73
72
74
COLOR_CHOICES = (('red' , 'Red' ), ('blue' , 'Blue' ), ('green' , 'Green' ))
75
+ DECIMAL_CHOICES = (('low' , decimal .Decimal ('0.1' )), ('medium' , decimal .Decimal ('0.5' )), ('high' , decimal .Decimal ('0.9' )))
73
76
74
77
75
78
class FieldOptionsModel (models .Model ):
@@ -82,6 +85,10 @@ class FieldOptionsModel(models.Model):
82
85
choices_field = models .CharField (max_length = 100 , choices = COLOR_CHOICES )
83
86
84
87
88
+ class MappingForChoicesWithNonStandardArgs (models .Model ):
89
+ choices_field_with_nonstandard_args = models .DecimalField (max_digits = 3 , decimal_places = 1 , choices = DECIMAL_CHOICES )
90
+
91
+
85
92
class TestModelSerializer (TestCase ):
86
93
def test_create_method (self ):
87
94
class TestSerializer (serializers .ModelSerializer ):
@@ -307,6 +314,13 @@ class Meta:
307
314
308
315
ChildSerializer ().fields
309
316
317
+ def test_choices_with_nonstandard_args (self ):
318
+ class ExampleSerializer (serializers .ModelSerializer ):
319
+ class Meta :
320
+ model = MappingForChoicesWithNonStandardArgs
321
+
322
+ ExampleSerializer ()
323
+
310
324
311
325
@pytest .mark .skipif (django .VERSION < (1 , 8 ),
312
326
reason = 'DurationField is only available for django1.8+' )
0 commit comments