models.py 2.85 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

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

    class Meta:
        abstract = True

class Course(BaseModel):

13
14
    name = models.CharField(max_length = 150)

Daniel W Bond's avatar
Daniel W Bond committed
15
    # ordering
16
17
    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
18
19
20
21

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

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

Daniel W Bond's avatar
Daniel W Bond committed
33
34
35
36
37
38
39
40
41
42
    # 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
43
44
45
# gen eds are coursecollections in programs
class CourseCollection(BaseModel):

46
47
    name = models.CharField(max_length = 150)

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

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

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

class Program(BaseModel):

58
59
    name = models.CharField(max_length = 150)

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

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

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

69
70
    isCompleted = models.BooleanField(False)

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

    def __unicode__(self):
        return self.name

Daniel W Bond's avatar
Daniel W Bond committed
77
# should inherit from the standard Django User Model
Daniel W Bond's avatar
Daniel W Bond committed
78
class Student(User):
Daniel W Bond's avatar
Daniel W Bond committed
79

80
81
    user = models.OneToOneField(User)

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

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

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

    def __unicode__(self):
        return self.name

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

class Trajectory(BaseModel):

99
    name = models.CharField(max_length = 150)
100
101

    # Takes courses
102
    previousCourses = models.ManyToManyField('Trajectory',)
Daniel W Bond's avatar
Daniel W Bond committed
103
104

    isPublic = models.BooleanField()
105
106
107
108
109
110
111
112

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

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

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