Fast API Tutorial, Part 14: Extra Models

preview_player
Показать описание
The content in this video has been seen in an earlier video but is still worth discussing itself. When you're building an API it may be useful to have descriptive models that are similar, but not used for the same things. For example, your BaseUser model may have a username, email, and date of birth and your UserInDB model may have all of these fields but also a `hashed_password` field. Your UserIn model may have a plain text password. Your UserOut model may have only the fields described in your BaseUser model.

In this video you'll see a basic introduction about how to incorporate this sort of model inheritance.

Рекомендации по теме
Комментарии
Автор

As of 08.2024 pydantic complains about base classes being overridden by non-annotated attributes, writing CarItem and PlaneItem this way works:
class CarItem(BaseItem):
type: str = "car"


class PlaneItem(BaseItem):
type: str = "plane"
size: int

MrAnt-hhbp
Автор

Really Awesome explanation and git code availability is also helpful. Thanks you very much.

ashwinpatidar
Автор

All I got into my mind during this video is "All my friends drive a low rider"

khiemtrantrong
Автор

Whats happening when you are passing user in into fake save user

mohammad-xyow
Автор

thanks for tutorial provided, very clear and nice.

Hanson-em
Автор

Double asterisk in python is called "Power Operator"

yomumuasim