models.py 3.28 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
62
    name = models.CharField(max_length = 150)

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

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

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

72
73
    isCompleted = models.BooleanField(False)

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

    def __unicode__(self):
        return self.name

Daniel W Bond's avatar
Daniel W Bond committed
80
# should inherit from the standard Django User Model
81
class Student(models.Model):
Daniel W Bond's avatar
Daniel W Bond committed
82

83
84
    user = models.OneToOneField(User)

Daniel W Bond's avatar
Daniel W Bond committed
85
86
    # does User have a slug field?

87
    alreadyTaken = models.ManyToManyField('Course', null=True)
88
    
89
    trajectory = models.ManyToManyField('Trajectory', null=True)
90
91

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

    class Meta:
Daniel W Bond's avatar
Daniel W Bond committed
94
        ordering = ('user',)
Daniel W Bond's avatar
Daniel W Bond committed
95
96
97
98
99

    def __unicode__(self):
        return self.name

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

102
103
104
105
106
107
def create_user_profile(sender, instance, created, **kwargs):
    if created:
        Student.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

108
109
class Trajectory(BaseModel):

110
    name = models.CharField(max_length = 150)
Daniel W Bond's avatar
Daniel W Bond committed
111
    slug = models.SlugField(max_length = 50, unique = True)
112
113

    # Takes courses
114
    previousCourses = models.ManyToManyField('Trajectory',)
Daniel W Bond's avatar
Daniel W Bond committed
115
116

    isPublic = models.BooleanField()
117
118
119
120
121

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

122
123
124
125
    class Meta:
        ordering = ('name',)
        verbose_name_plural = "trajectories"

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