-
Notifications
You must be signed in to change notification settings - Fork 3
/
models.py
78 lines (55 loc) · 1.86 KB
/
models.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import peewee
import constants
class BaseModel(peewee.Model):
class Meta:
database = constants.db
class Branch(BaseModel):
code = peewee.FixedCharField(unique=True)
name = peewee.CharField()
class Student(BaseModel):
student_id = peewee.CharField()
name = peewee.CharField()
branch_id = peewee.CharField()
batch = peewee.IntegerField()
cgpa = peewee.FloatField()
course = peewee.CharField(choices = (('reg', 'regular'), ('le', 'lateral-entry')))
is_visible = peewee.BooleanField(default=True)
class Meta:
primary_key = peewee.CompositeKey('student_id', 'batch')
order_by = ('student_id',)
class Exam(BaseModel):
student_id = peewee.CharField()
semester_id = peewee.CharField()
sgpa = peewee.FloatField()
credits = peewee.IntegerField()
class Meta:
primary_key = peewee.CompositeKey('student_id', 'semester_id')
class Score(BaseModel):
student_id = peewee.CharField()
subject_id = peewee.CharField()
grade = peewee.FixedCharField()
semester_id = peewee.CharField()
class Meta:
primary_key = peewee.CompositeKey('student_id', 'subject_id')
class Semester(BaseModel):
code = peewee.PrimaryKeyField()
batch = peewee.IntegerField()
num = peewee.IntegerField() # from 1 to 8
class Subject(BaseModel):
code = peewee.CharField()
name = peewee.CharField()
credits = peewee.IntegerField()
class Meta:
primary_key = peewee.CompositeKey('code')
class BulkQuery(BaseModel):
student_id = peewee.CharField()
name = peewee.CharField()
sgpa = peewee.FloatField()
def addTo(table, data_source):
with db.atomic():
if table == "Branch":
Branch.insert_many(data_source).execute()
elif table == "Semester":
Semester.insert_many(data_source).execute()
print "Done inserting"