models.py 2.66 KB
Newer Older
Daniel Warren Bond's avatar
Daniel Warren Bond committed
1
2
from django.db import models

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

    class Meta:
        abstract = True

class Course(BaseModel):

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

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

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

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

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

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

class Program(BaseModel):

    # courseCollections
55
    courseReqs =  models.ManyToManyField('CourseCollection',)
Daniel W Bond's avatar
Daniel W Bond committed
56
57

    # major or minor or gened
Daniel W Bond's avatar
Daniel W Bond committed
58
    programType = models.CharField(max_length = 25)
Daniel W Bond's avatar
Daniel W Bond committed
59
60

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

    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name

Daniel W Bond's avatar
Daniel W Bond committed
69
70
71
# should inherit from the standard Django User Model
class Student(BaseModel):

72
73
    alreadyTaken = models.ManyToManyField('Course', null=True)
    trajectory = models.ManyToManyField('Trajectory', null=True)
74
75

    # aka username, etc should all be here
Daniel W Bond's avatar
Daniel W Bond committed
76
77
78
79
80
81
82
83
84
85

    slug = models.SlugField(max_length = 50)

    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name

    def get_absolute_url(self):
Daniel W Bond's avatar
Daniel W Bond committed
86
        return self.name
87
88
89

class Trajectory(BaseModel):

Daniel W Bond's avatar
Daniel W Bond committed
90
    # name randomly generated
91
92

    # Takes courses
Daniel W Bond's avatar
Daniel W Bond committed
93
94
95
    previousCourses = models.ManyToManyField('Course',)

    isPublic = models.BooleanField()
96
97
98
99
100
101
102
103

    # 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
104
        return '/%s/' % self.slug