Closed lucasbrahm closed 8 months ago
Also please update changlog.
Made the adjustments. Also updated the docstring. Not sure how to add it to the changelog
Just ref CHANGELOG.rst
Is it ok?
Thanks!
We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report. To ensure accuracy in future PRs, please see these guidelines. A quick fix for this PR: rebase it; your next report should be accurate.
Totals | |
---|---|
Change from base Build 6502900700: | 0.0% |
Covered Lines: | 5756 |
Relevant Lines: | 6408 |
Pydantic provides Before, After, Wrap and Plain validators, Field validators and Model validators. This is nice for cleaning and validating fields. For example, you can remove any non numeric characters for a phone field and then validate, like this:
So both phone '123-4567' and '1234567' will be validated and it will be stored as '1234567'.
The problem of tortoise "pydantic_model_creator" is that it exposes few options when calling pydantic "create_model". Also, tortoise field validators only validate data, without modifying/cleaning data.
Fortunately, you can add validators in pyndatic by passing a dict to the "validators" argument when calling "create_model".
The idea of this PR is to add "validators" option in tortoise "pydantic_model_creator" which will be used during the call of pydantic "create_model"
So in the end it would be like this: