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

Conversation

mahdirahimi1999
Copy link
Contributor

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

Description

This commit adds the max_digits and decimal_places attributes to the list of attributes included in the get_field_info method of the SimpleMetadata class in the Django Rest Framework. These attributes provide additional information about decimal fields, which was not previously included in the metadata. By adding these attributes to the output of the method, clients consuming the API will have more complete information about the fields in the serialized data, allowing them to make more informed decisions about how to interact with the API. This change was made in response to user feedback and is not expected to have any negative impact on existing functionality.

before change

{
    "name": "My View",
    "description": "This is a view.",
    "renders": ["application/json"],
    "parses": ["application/json"],
    "actions": {
        "PUT": {
            "type": "nested object",
            "required": true,
            "children": {
                "id": {
                    "type": "integer",
                    "required": true,
                    "read_only": false,
                    "label": "ID",
                    "help_text": "The ID of the object."
                },
                "name": {
                    "type": "string",
                    "required": true,
                    "read_only": false,
                    "label": "Name",
                    "help_text": "The name of the object."
                },
                "price": {
                    "type": "decimal",
                    "required": true,
                    "read_only": false,
                    "label": "Price",
                    "help_text": "The price of the object.",
                }
            }
        }
    }
}

after change

{
    "name": "My View",
    "description": "This is a view.",
    "renders": ["application/json"],
    "parses": ["application/json"],
    "actions": {
        "PUT": {
            "type": "nested object",
            "required": true,
            "children": {
                "id": {
                    "type": "integer",
                    "required": true,
                    "read_only": false,
                    "label": "ID",
                    "help_text": "The ID of the object."
                },
                "name": {
                    "type": "string",
                    "required": true,
                    "read_only": false,
                    "label": "Name",
                    "help_text": "The name of the object."
                },
                "price": {
                    "type": "decimal",
                    "required": true,
                    "read_only": false,
                    "label": "Price",
                    "help_text": "The price of the object.",
                    "max_digits": 6,
                    "decimal_places": 2
                }
            }
        }
    }
}

@mahdirahimi1999 mahdirahimi1999 changed the title Refactor get_field_info method to include max_digits and decimal_places attributes in SimpleMetadata class Refactor get_field_info method to include max_digits and decimal_places attributes Apr 12, 2023
@mahdirahimi1999 mahdirahimi1999 changed the title Refactor get_field_info method to include max_digits and decimal_places attributes Refactor get_field_info method to include max_digits and decimal_places attributes in SimpleMetadata class Apr 12, 2023
@@ -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.

rest_framework/metadata.py Outdated Show resolved Hide resolved
@auvipy auvipy closed this Apr 13, 2023
@auvipy auvipy reopened this Apr 13, 2023
@auvipy
Copy link
Member

auvipy commented Apr 13, 2023

interestingly the CI tests are not running now

@mahdirahimi1999
Copy link
Contributor Author

interestingly the CI tests are not running now

Do I have to do anything special?

@auvipy
Copy link
Member

auvipy commented Apr 15, 2023

we need some work to fix the codecov issue in the CI first

@mahdirahimi1999
Copy link
Contributor Author

we need some work to fix the codecov issue in the CI first

OK, thanks,
good luck.

@mahdirahimi1999
Copy link
Contributor Author

I think the CI problem is fixed...

@auvipy
Copy link
Member

auvipy commented Apr 19, 2023

yup seems to be released again https://pypi.org/project/codecov/#history

@auvipy auvipy closed this Apr 19, 2023
@auvipy auvipy reopened this Apr 19, 2023
@mahdirahimi1999
Copy link
Contributor Author

yup seems to be released again https://pypi.org/project/codecov/#history

Could you tell me if this pull request has been merged or not?

@auvipy auvipy merged commit 1ce0853 into encode:master Apr 27, 2023
9 checks passed
@mahdirahimi1999 mahdirahimi1999 deleted the feature/max-digits-decimal-places branch April 30, 2023 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants