models.py 2.87 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
Daniel W Bond's avatar
Daniel W Bond committed
52
    numberOfCoursesReq = models.IntegerField()
Daniel W Bond's avatar
Daniel W Bond committed
53
54
55

class Program(BaseModel):

56
57
    name = models.CharField(max_length = 150)

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

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

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

    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name

Daniel W Bond's avatar
Daniel W Bond committed
73
74
75
# should inherit from the standard Django User Model
class Student(BaseModel):

76
77
78
79
    user = models.OneToOneField(User)
    # might there be a problem with the name field in base?

    # should this be a trajectory instead? >_>
80
    alreadyTaken = models.ManyToManyField('Course', null=True)
81
    
82
    trajectory = models.ManyToManyField('Trajectory', null=True)
83
84

    # aka username, etc should all be here
Daniel W Bond's avatar
Daniel W Bond committed
85
86
87
88
89
90
91
92

    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name

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

class Trajectory(BaseModel):

97
    name = models.CharField(max_length = 150)
98
99

    # Takes courses
Daniel W Bond's avatar
Daniel W Bond committed
100
101
102
    previousCourses = models.ManyToManyField('Course',)

    isPublic = models.BooleanField()
103
104
105
106
107
108
109
110

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