models.py 3.27 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
31
32
33
    def isUpperClass:
      if courseNumber > 300:
          return True:
      else:
          return False

Daniel W Bond's avatar
Daniel W Bond committed
34
35
36
    # available next semester?
    # CRN
    # section number
Daniel W Bond's avatar
Daniel W Bond committed
37
    # professor
Daniel W Bond's avatar
Daniel W Bond committed
38
    
Daniel W Bond's avatar
Daniel W Bond committed
39
    # Course may need program-specific information
40

Daniel W Bond's avatar
Daniel W Bond committed
41
42
43
44
45
46
47
48
49
50
    # 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
51
52
53
# gen eds are coursecollections in programs
class CourseCollection(BaseModel):

54
55
    name = models.CharField(max_length = 150)

Daniel W Bond's avatar
Daniel W Bond committed
56
    # a number of courses
57
    courses = models.ManyToManyField('Course',)
Daniel W Bond's avatar
Daniel W Bond committed
58

Daniel W Bond's avatar
Daniel W Bond committed
59
    # how many of those are required
60
61
62
    numReq = models.IntegerField()

    isCompleted = models.BooleanField(False)
Daniel W Bond's avatar
Daniel W Bond committed
63
64
65

class Program(BaseModel):

66
67
    name = models.CharField(max_length = 150)

Daniel W Bond's avatar
Daniel W Bond committed
68
    # courseCollections
69
    courseReqs =  models.ManyToManyField('CourseCollection',)
Daniel W Bond's avatar
Daniel W Bond committed
70
71

    # major or minor or gened
Daniel W Bond's avatar
Daniel W Bond committed
72
    programType = models.CharField(max_length = 25)
Daniel W Bond's avatar
Daniel W Bond committed
73
74

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

77
78
    isCompleted = models.BooleanField(False)

Daniel W Bond's avatar
Daniel W Bond committed
79
80
81
82
83
84
    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name

Daniel W Bond's avatar
Daniel W Bond committed
85
# should inherit from the standard Django User Model
86
class Student(models.Model):
Daniel W Bond's avatar
Daniel W Bond committed
87

88
89
    user = models.OneToOneField(User)

90
    alreadyTaken = models.ManyToManyField('Course', null=True)
91
    
92
    trajectory = models.ManyToManyField('Trajectory', null=True)
93
94

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

    class Meta:
Daniel W Bond's avatar
Daniel W Bond committed
97
        ordering = ('user',)
Daniel W Bond's avatar
Daniel W Bond committed
98
99
100
101
102

    def __unicode__(self):
        return self.name

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

105
106
107
108
109
110
def create_user_profile(sender, instance, created, **kwargs):
    if created:
        Student.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

111
112
class Trajectory(BaseModel):

113
    name = models.CharField(max_length = 150)
114
115

    # Takes courses
116
    previousCourses = models.ManyToManyField('Trajectory',)
Daniel W Bond's avatar
Daniel W Bond committed
117
118

    isPublic = models.BooleanField()
119
120
121
122
123

    # 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()

124
125
126
127
    class Meta:
        ordering = ('name',)
        verbose_name_plural = "trajectories"

128
129
130
    def get_absolute_url(self):
        return 'my-trajectories/%s/' % self.slug

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