Models & Fields
Models & Fields
Chapter 2
Models & Fields
Object-Relational Mapping
SQL table
Python Class
Model
CLICK HERE
Models
1. The model is defined in the file
model.py module/models/model.py
CLICK HERE
module/
│
├─ models/
│ ├─ __init__.py (2)
│ └─ model.py (1)
│
└─ __init__.py (3)
Fields
field_1 = fields.Boolean()
field_2 = fields.Integer()
Fields
CLICK HERE
Simple fields
Boolean - True / False
● Required - True or False, if true then record cannot be saved in database with an empty/null value
● …
Chapter 2 1) In the estate module, add a new directory to store our models
python files.
New model
2) In this directory, create a new python file for the
estate_property table (don’t forget to add the __init__ too).
3) When the files are created, add a minimum definition for the
estate.property model.
Help: For now, just remember that in the future, we will try to have one model
per file in order to keep the project as object-oriented and clean as possible.
Exercise Add basic fields to the Real Estate Property table.
PARTNERS
Field Type
Chapter 2 name Char
date_availability Date
expected_price Float
selling_price Float
bedrooms Integer
living_area Integer
facades Integer
Exercise Add basic fields to the Real Estate Property table.
PARTNERS
Field Type
Chapter 2 garage Boolean
CLICK HERE
Exercise Set attributes for the following fields
PARTNERS
name required
New model
expected_price required
Add fields
Fields attributes