Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need tests to avoid regression

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

auvipy marked this conversation as resolved.
Show resolved Hide resolved
]

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