-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_data.py
More file actions
56 lines (43 loc) · 1.37 KB
/
add_data.py
File metadata and controls
56 lines (43 loc) · 1.37 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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!")
data = [
{ 'name': 'Sandhya', 'admission': datetime.date(2018, 10, 20) },
{ 'name': 'Aarav', 'admission': datetime.date(2018, 10, 12) },
{ 'name': 'Mohammed', 'admission': datetime.date(2018, 10, 5) },
{ 'name': 'Vihaan', 'admission': datetime.date(2018, 10, 28) },
{ 'name': 'Aditya', 'admission': datetime.date(2018, 10, 14) },
{ 'name': 'Sai', 'admission': datetime.date(2018, 10, 22) },
{ 'name': 'Dev', 'admission': datetime.date(2018, 10, 28) }
]
with database.atomic():
query = Students.insert_many(data)
query.execute()