models.py 3.4 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
    name = models.CharField(max_length = 150)
Daniel W Bond's avatar
Daniel W Bond committed
16
    slug = models.SlugField(max_length = 50, unique=True)
17

Daniel W Bond's avatar
Daniel W Bond committed
18
    # ordering
19
20
    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
21
22
23
24

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

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

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

49
50
    name = models.CharField(max_length = 150)

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

Daniel W Bond's avatar
Daniel W Bond committed
54
    # how many of those are required
55
56
57
    numReq = models.IntegerField()

    isCompleted = models.BooleanField(False)
Daniel W Bond's avatar
Daniel W Bond committed
58
59
60

class Program(BaseModel):

61
    name = models.CharField(max_length = 150)
62
    # slug = models.SlugField(max_length = 50, unique = True)
63

Daniel W Bond's avatar
Daniel W Bond committed
64
    # courseCollections
65
    courseReqs =  models.ManyToManyField('CourseCollection',)
Daniel W Bond's avatar
Daniel W Bond committed
66
67

    # major or minor or gened
Daniel W Bond's avatar
Daniel W Bond committed
68
    programType = models.CharField(max_length = 25)
Daniel W Bond's avatar
Daniel W Bond committed
69
70

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

73
74
    isCompleted = models.BooleanField(False)

Daniel W Bond's avatar
Daniel W Bond committed
75
76
77
78
79
80
    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name

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

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

87
88
    user = models.OneToOneField(User)

Daniel W Bond's avatar
Daniel W Bond committed
89
90
    # does User have a slug field?

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

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

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

    def __unicode__(self):
        return self.name

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

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

post_save.connect(create_user_profile, sender=User)

112
113
class Trajectory(BaseModel):

114
    name = models.CharField(max_length = 150)
Daniel W Bond's avatar
Daniel W Bond committed
115
    slug = models.SlugField(max_length = 50, unique = True)
116
117

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

120
121
122
    # def getPreviousTrajectory(Trajectory):
        # return Trajectory

Daniel W Bond's avatar
Daniel W Bond committed
123
    isPublic = models.BooleanField()
124

125
    # semesters since entering college
126
127
    semester = models.IntegerField()

128
129
130
131
    class Meta:
        ordering = ('name',)
        verbose_name_plural = "trajectories"

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