Models#

Creating a model#

Here is a sample model which uses sqlalchemy

 1
 2class ContactMessage(db.Model):
 3
 4    __tablename__ = "contact"
 5    id = db.Column(db.Integer, primary_key=True)
 6    created_date = db.Column(db.DateTime, default=datetime.now())
 7    name = db.Column(db.String(100))
 8    email = db.Column(db.String(100))
 9    message = db.Column(db.String(1024))
10
11    def insert(self):
12        db.session.add(self)
13        db.session.commit()
14
15    def update(self):
16        db.session.commit()
17
18    def delete(self):
19        db.session.delete(self)
20        db.session.commit()

🔩 Migrations#

Note

You can run

shopyo <command>

or

python manage.py <command>

In case of change to models, do

python manage.py db migrate
python manage.py db upgrade