Refactor get_field_info method to include max_digits and decimal_places attributes in SimpleMetadata class (#8943)

* Refactor get_field_info method to include max_digits and decimal_places attributes in SimpleMetadata class

* Add new test to check decimal_field_info_type

* Update rest_framework/metadata.py

---------

Co-authored-by: Mahdi <mahdi@Mahdis-MacBook-Pro.local>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
This commit is contained in:
Mahdi Rahimi 2023-04-27 07:54:13 +03:30 committed by GitHub
parent 38a74b42da
commit 1ce0853ac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -124,7 +124,8 @@ class SimpleMetadata(BaseMetadata):
attrs = [
'read_only', 'label', 'help_text',
'min_length', 'max_length',
'min_value', 'max_value'
'min_value', 'max_value',
'max_digits', 'decimal_places'
]
for attr in attrs:

View File

@ -324,6 +324,13 @@ class TestSimpleMetadataFieldInfo(TestCase):
)
assert 'choices' not in field_info
def test_decimal_field_info_type(self):
options = metadata.SimpleMetadata()
field_info = options.get_field_info(serializers.DecimalField(max_digits=18, decimal_places=4))
assert field_info['type'] == 'decimal'
assert field_info['max_digits'] == 18
assert field_info['decimal_places'] == 4
class TestModelSerializerMetadata(TestCase):
def test_read_only_primary_key_related_field(self):