July 2018
Intermediate to advanced
324 pages
8h 14m
English
A model is an entity that represents the essential fields and structure of the data. Each model class represents a database table. In our case, we need to have a single database table. Hence, we will create a single model class to store the data. The following is the code snippet of models.py.
File—models.py:
import osimport datetimefrom shutil import copyfilefrom peewee import *# Copy our working DB to /tmp..db_name = 'quote_database.db'src = os.path.abspath(db_name)dst = "/tmp/{}".format(db_name)copyfile(src, dst)db = SqliteDatabase(dst)class QuoteModel(Model): class Meta: database = db id = IntegerField(primary_key= True) quote = TextField() author = CharField() category = CharField() created_at = DateTimeField(default= ...Read now
Unlock full access