Python-powered chat apps with Twilio and SendGrid Transcripts
Chapter: Creating the Flask Python web app
Lecture: A little more Pydantic validation

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's look at one more super quick thing we can do to make our pydantic model data exchange a little tiny bit better over at pydantic.
0:08 They have this thing called model config, where you can set all sorts of information and auto transformations and validation for your models
0:15 so we can set the title. So how it refers to itself, things like strip off any white space on any strings or what
0:24 the maximum or minimum length of any string we're willing to accept is, and so on, the way you do it is real simple.
0:30 There's an example right here is you create an inner class called config, and then you set those elements those validations there.
0:38 So let's go over here and go back to our cake and we'll say, class config. What we want to say is any string strip the white space.
0:49 So, for example, if the topping somehow got chocolate space or space chocolate, really, when you just wanted to say chocolate and of course,
0:57 we could go write code to say if there's a string here and make sure that we take away any spaces, tabs,
1:03 new lines and so on in there but we don't have to. We can just use this. But we're going to put this on all of our
1:10 various classes like this. If you want to do further validation like the price has to be greater than zero, but less than some number or whatever,
1:21 that makes sense. You know, you can add all those types of things here. We're just going to keep it simple.
1:25 But I wanted to point out that we do have these really advanced automatic conversion and
1:29 validation features of pydantic that we can layer in with this inner config class.


Talk Python's Mastodon Michael Kennedy's Mastodon