What is the best way to validate a field using ormar + pydantic #411
-
I would like to validate some fields, for example, username fields larger than 3 characters. What is the best way to handle this. If possible please show me an example. Here is a small snippet to start with:
Of course I could check the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For each field in ormar you can use all of the pydantic Field arguments (https://pydantic-docs.helpmanual.io/usage/schema/#field-customisation). So in you case simply add If your definition of pydantic Field is very fancy, you can force replace the field: https://collerek.github.io/ormar/fields/common-parameters/#overwrite_pydantic_type. |
Beta Was this translation helpful? Give feedback.
For each field in ormar you can use all of the pydantic Field arguments (https://pydantic-docs.helpmanual.io/usage/schema/#field-customisation).
So in you case simply add
min_length
argument to ormar string field.If your definition of pydantic Field is very fancy, you can force replace the field: https://collerek.github.io/ormar/fields/common-parameters/#overwrite_pydantic_type.