models.py 3.16 KB
Newer Older
Daniel Warren Bond's avatar
Daniel Warren Bond committed
1
from django.db import models
2
from django.contrib.auth.models import User
Daniel Warren Bond's avatar
Daniel Warren Bond committed
3

4
5
from django.db.models.signals import post_save

Daniel W Bond's avatar
Daniel W Bond committed
6
class BaseModel(models.Model):
Daniel W Bond's avatar
Daniel W Bond committed
7
    created = models.DateTimeField('Created', auto_now_add=True, editable=False)
Daniel W Bond's avatar
Daniel W Bond committed
8
9
10
11
12
13
14
    last_modified = models.DateTimeField('Last Modified', auto_now=True)

    class Meta:
        abstract = True

class Course(BaseModel):

15
16
    name = models.CharField(max_length = 150)

Daniel W Bond's avatar
Daniel W Bond committed
17
    # ordering
18
19
    prerequisites = models.ManyToManyField('Course', related_name = 'prereqField', null=True)
    corequisites = models.ManyToManyField('Course', related_name = 'coreqField', null=True)
Daniel W Bond's avatar
Daniel W Bond committed
20
21
22
23

    # basic course information
    department = models.CharField(max_length = 150)
    departmentAbbr = models.CharField(max_length = 5)
Daniel W Bond's avatar
Daniel W Bond committed
24
    courseNumber = models.CharField(max_length = 3)
25
26
    courseDescription = models.TextField()
    credits = models.IntegerField()
Daniel W Bond's avatar
Daniel W Bond committed
27
28
29
30

    # available next semester?
    # CRN
    # section number
Daniel W Bond's avatar
Daniel W Bond committed
31
    # professor
Daniel W Bond's avatar
Daniel W Bond committed
32
    
Daniel W Bond's avatar
Daniel W Bond committed
33
    # Course may need program-specific information
34

Daniel W Bond's avatar
Daniel W Bond committed
35
36
37
38
39
40
41
42
43
44
    # default sorting order in admin
    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name

    def get_absolute_url(self):
        return '/courses/%s/' % self.slug

Daniel W Bond's avatar
Daniel W Bond committed
45
46
47
# gen eds are coursecollections in programs
class CourseCollection(BaseModel):

48
49
    name = models.CharField(max_length = 150)

Daniel W Bond's avatar
Daniel W Bond committed
50
    # a number of courses
51
    courses = models.ManyToManyField('Course',)
Daniel W Bond's avatar
Daniel W Bond committed
52

Daniel W Bond's avatar
Daniel W Bond committed
53
    # how many of those are required
54
55
56
    numReq = models.IntegerField()

    isCompleted = models.BooleanField(False)
Daniel W Bond's avatar
Daniel W Bond committed
57
58
59

class Program(BaseModel):

60
61
    name = models.CharField(max_length = 150)

Daniel W Bond's avatar
Daniel W Bond committed
62
    # courseCollections
63
    courseReqs =  models.ManyToManyField('CourseCollection',)
Daniel W Bond's avatar
Daniel W Bond committed
64
65

    # major or minor or gened
Daniel W Bond's avatar
Daniel W Bond committed
66
    programType = models.CharField(max_length = 25)
Daniel W Bond's avatar
Daniel W Bond committed
67
68

    # is BA, BS, Honors
Daniel W Bond's avatar
Daniel W Bond committed
69
    degreeType = models.CharField(max_length = 25)
Daniel W Bond's avatar
Daniel W Bond committed
70

71
72
    isCompleted = models.BooleanField(False)

Daniel W Bond's avatar
Daniel W Bond committed
73
74
75
76
77
78
    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name

Daniel W Bond's avatar
Daniel W Bond committed
79
# should inherit from the standard Django User Model
80
class Student(models.Model):
Daniel W Bond's avatar
Daniel W Bond committed
81

82
83
    user = models.OneToOneField(User)

84
    alreadyTaken = models.ManyToManyField('Course', null=True)
85
    
86
    trajectory = models.ManyToManyField('Trajectory', null=True)
87
88

    # aka username, etc should all be here
Daniel W Bond's avatar
Daniel W Bond committed
89
90

    class Meta:
Daniel W Bond's avatar
Daniel W Bond committed
91
        ordering = ('user',)
Daniel W Bond's avatar
Daniel W Bond committed
92
93
94
95
96

    def __unicode__(self):
        return self.name

    def get_absolute_url(self):
Daniel W Bond's avatar
Daniel W Bond committed
97
        return self.name
98

99
100
101
102
103
104
def create_user_profile(sender, instance, created, **kwargs):
    if created:
        Student.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

105
106
class Trajectory(BaseModel):

107
    name = models.CharField(max_length = 150)
108
109

    # Takes courses
110
    previousCourses = models.ManyToManyField('Trajectory',)
Daniel W Bond's avatar
Daniel W Bond committed
111
112

    isPublic = models.BooleanField()
113
114
115
116
117

    # this isn't exactly done correctly-- ideally courses should be elements
    # of a list, not one created for each and every semester
    semester = models.IntegerField()

118
119
120
121
    class Meta:
        ordering = ('name',)
        verbose_name_plural = "trajectories"

122
123
124
    def get_absolute_url(self):
        return 'my-trajectories/%s/' % self.slug

Daniel W Bond's avatar
Daniel W Bond committed
125
        return '/%s/' % self.slug