Skip to content

Commit

Permalink
Refactor get_field_info method to include max_digits and decimal_plac…
Browse files Browse the repository at this point in the history
…es 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>
  • Loading branch information
3 people committed Apr 27, 2023
1 parent 38a74b4 commit 1ce0853
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rest_framework/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def get_field_info(self, field):
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:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ def test_related_field_choices(self):
)
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):
Expand Down

0 comments on commit 1ce0853

Please sign in to comment.