Creating the House and HouseChecker Models
Explore how to create the House and HouseChecker models in the Flask Core app. Learn to define attributes, use dataclasses for serialization, and enforce unique constraints to maintain data integrity.
We'll cover the following...
We'll cover the following...
Creating the House model
In our Core app, the House model will have the following attributes:
A name for identification of each house.
An image data of each house for visual recognition.
A description of each house.
First, we'll import the dataclass from dataclasses, like so:
from dataclasses import dataclass
Then, we can create our House model inside the core.py file, as shown below:
Line 1: We instantiate the
dataclasswith@dataclass. This decorator enforces data validation and makes the data types in this model easily serializable. ...