-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathmodels.py
69 lines (52 loc) · 2.23 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
import calendar
from django.db import models
class Calendar(models.Model):
date = models.DateField(primary_key=True)
remark = models.TextField(max_length=255, blank=True)
class_scheduled = models.BooleanField(default=True)
class Meta:
verbose_name_plural = 'Calendar'
def __str__(self):
return str(self.date)
class Section(models.Model):
# For grouping and sorting
section_id = models.CharField(max_length=5, unique=True)
name = models.CharField(max_length=30, unique=True)
is_parent_section = models.BooleanField(default=False)
parent_section = models.ForeignKey(
'self', null=True, blank=True, on_delete=models.SET_NULL, limit_choices_to={'is_parent_section': True})
def __str__(self):
return self.name
class Schedule(models.Model):
# They won't ever change and will give us dropdown in Admin site
DAY = [((i+1)%7, calendar.day_name[i]) for i in range(0, 7)]
SUBJECT = (
('eng', "English"),
('hin', "Hindi"),
('mat', "Mathematics"),
('sci', "Science"),
('ssc', "Social Science"),
('mab', "Mental Ability"),
)
day = models.IntegerField(choices=DAY)
section = models.ForeignKey(Section, on_delete=models.CASCADE)
subject = models.CharField(max_length=3, choices=SUBJECT)
class Meta:
unique_together = (('day', 'section'),)
def __str__(self):
return f'{self.get_day_display()} - {self.section.name} - {self.get_subject_display()}'
class ClassworkHomework(models.Model):
cal_date = models.ForeignKey(Calendar, on_delete=models.PROTECT)
section = models.ForeignKey(Section, on_delete=models.CASCADE)
# Content to be taught
to_be_taught = models.TextField(max_length=1023, blank=True)
subject_taught = models.CharField(max_length=3, choices=Schedule.SUBJECT)
cw = models.TextField(max_length=1023, blank=True)
hw = models.TextField(max_length=1023, blank=True)
comment = models.TextField(max_length=1023, blank=True)
class Meta:
unique_together = (('cal_date', 'section'),)
verbose_name = 'ClassWork/HomeWork'
verbose_name_plural = 'ClassWork/HomeWork'
def __str__(self):
return f'{self.cal_date} - {self.section.name}'