-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
42 lines (31 loc) · 842 Bytes
/
models.py
File metadata and controls
42 lines (31 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import peewee
import datetime
database = peewee.SqliteDatabase("test.db")
class Students(peewee.Model):
"""
ORM model of the Students table
"""
name = peewee.CharField()
admission = peewee.DateField(default=datetime.date.today)
class Meta:
database = database
class Schools(peewee.Model):
"""
ORM model of Schools table
"""
school = peewee.CharField()
location = peewee.CharField()
class Meta:
database = database
if __name__ == "__main__":
"""
Handling exceptions
"""
try:
Students.create_table()
except peewee.OperationalError:
print ("Students table already exists!")
try:
Schools.create_table()
except peewee.OperationalError:
print ("Schools table already exists!")