models.py 2.96 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
78
79
# should inherit from the standard Django User Model
class Student(BaseModel):

80
81
82
83
    user = models.OneToOneField(User)
    # might there be a problem with the name field in base?

    # should this be a trajectory instead? >_>
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
91
92
93
94
95
96

    class Meta:
        ordering = ('name',)

    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

class Trajectory(BaseModel):

101
    name = models.CharField(max_length = 150)
102
103

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

    isPublic = models.BooleanField()
107
108
109
110
111
112
113
114

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