From a21f0763ee877f0c86f254a5d60f70b1002faa68 Mon Sep 17 00:00:00 2001 From: Dror Atariah Date: Mon, 18 Jul 2022 09:06:31 +0200 Subject: [PATCH] Improved example ind models doc (#4231) Co-authored-by: Hasan Ramezani --- docs/usage/models.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/usage/models.md b/docs/usage/models.md index 9ed6a03..bddb2ec 100644 --- a/docs/usage/models.md +++ b/docs/usage/models.md @@ -33,12 +33,16 @@ default value, and so a type annotation is not required (however note [this](#fi order when some fields do not have type annotations). ```py user = User(id='123') +user_x = User(id='123.45') ``` `user` here is an instance of `User`. Initialisation of the object will perform all parsing and validation, if no `ValidationError` is raised, you know the resulting model instance is valid. ```py assert user.id == 123 +assert user_x.id == 123 +assert isinstance(user_x.id, int) # Note that 123.45 was casted to an int and its value is 123 ``` +More details on the casting in the case of `user_x` can be found in [Data Conversion](#data-conversion). Fields of a model can be accessed as normal attributes of the user object. The string '123' has been cast to an int as per the field type ```py