Skip to content

Models

myapp.models

CommonModel

Bases: Model

A common abstract :class:django.db.models.Model with common fields for all "real" Models.

Source code in myapp/models.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class CommonModel(models.Model):
    """
    A common abstract :class:`django.db.models.Model` with common fields for all "real" Models.
    """

    id = models.UUIDField(
        primary_key=True,
        default=uuid.uuid4,
        editable=False,
        help_text="globally unique id (UUID4)",
    )
    """Unique object ID"""
    effective_start_date = models.DateField(
        default=None,
        blank=True,
        null=True,
        help_text="date when this instance becomes valid",
    )
    """Date when this instance becomes valid"""
    effective_end_date = models.DateField(
        default=None,
        blank=True,
        null=True,
        help_text="date when this instance becomes invalid",
    )
    """Date when this instance becomes invalid"""
    last_mod_user_name = models.CharField(
        default=None,
        null=True,
        max_length=80,
        help_text="who last modified this instance",
    )
    """Who last modified this instance"""
    last_mod_date = models.DateField(auto_now=True, help_text="when they modified it")
    """Wheno they modified it"""

    class Meta:
        abstract = True

id = models.UUIDField(primary_key=True, default=(uuid.uuid4), editable=False, help_text='globally unique id (UUID4)') class-attribute instance-attribute

Unique object ID

effective_start_date = models.DateField(default=None, blank=True, null=True, help_text='date when this instance becomes valid') class-attribute instance-attribute

Date when this instance becomes valid

effective_end_date = models.DateField(default=None, blank=True, null=True, help_text='date when this instance becomes invalid') class-attribute instance-attribute

Date when this instance becomes invalid

last_mod_user_name = models.CharField(default=None, null=True, max_length=80, help_text='who last modified this instance') class-attribute instance-attribute

Who last modified this instance

last_mod_date = models.DateField(auto_now=True, help_text='when they modified it') class-attribute instance-attribute

Wheno they modified it

Meta

Source code in myapp/models.py
43
44
class Meta:
    abstract = True
abstract = True class-attribute instance-attribute

Course

Bases: CommonModel

A course of instruction. e.g. COMSW1002 Computing in Context

Source code in myapp/models.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class Course(CommonModel):
    """
    A course of instruction. e.g. COMSW1002 Computing in Context
    """

    school_bulletin_prefix_code = models.CharField(max_length=10)
    """School bulletin prefix_code"""
    suffix_two = models.CharField(
        max_length=2, help_text="two-character identifier suffix"
    )
    """Two-character inditifier suffix"""
    subject_area_code = models.CharField(max_length=10, help_text="Subject")
    """Subject area code"""
    course_number = models.CharField(
        max_length=10,
        help_text='"Shortcut" identifier (formerly for touch-tone registration)',
    )
    course_identifier = models.CharField(
        max_length=9,
        unique=True,
        help_text="Course identifier (one-character suffix)",
        validators=(
            validators.RegexValidator(regex="[A-Z]{4}[0-9]{4}[A-Z]"),
            validators.MinLengthValidator(limit_value=9),
        ),
    )
    course_name = models.CharField(max_length=80, help_text="Course official title")
    course_description = models.TextField(help_text="Course description")

    class Meta:
        ordering = ["course_number"]

    def __str__(self):
        return "%s,%s,%s,%s" % (
            self.id,
            self.course_number,
            self.course_identifier,
            self.course_name,
        )

school_bulletin_prefix_code = models.CharField(max_length=10) class-attribute instance-attribute

School bulletin prefix_code

suffix_two = models.CharField(max_length=2, help_text='two-character identifier suffix') class-attribute instance-attribute

Two-character inditifier suffix

subject_area_code = models.CharField(max_length=10, help_text='Subject') class-attribute instance-attribute

Subject area code

course_number = models.CharField(max_length=10, help_text='"Shortcut" identifier (formerly for touch-tone registration)') class-attribute instance-attribute

course_identifier = models.CharField(max_length=9, unique=True, help_text='Course identifier (one-character suffix)', validators=(validators.RegexValidator(regex='[A-Z]{4}[0-9]{4}[A-Z]'), validators.MinLengthValidator(limit_value=9))) class-attribute instance-attribute

course_name = models.CharField(max_length=80, help_text='Course official title') class-attribute instance-attribute

course_description = models.TextField(help_text='Course description') class-attribute instance-attribute

Meta

Source code in myapp/models.py
76
77
class Meta:
    ordering = ["course_number"]
ordering = ['course_number'] class-attribute instance-attribute

__str__()

Source code in myapp/models.py
79
80
81
82
83
84
85
def __str__(self):
    return "%s,%s,%s,%s" % (
        self.id,
        self.course_number,
        self.course_identifier,
        self.course_name,
    )

CourseTerm

Bases: CommonModel

A specific course term (year+semester) instance. e.g. 20183COMSW1002

Source code in myapp/models.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
class CourseTerm(CommonModel):
    """
    A specific course term (year+semester) instance.
    e.g. 20183COMSW1002
    """

    term_identifier = models.CharField(
        max_length=14,
        unique=True,
        validators=(
            validators.RegexValidator(regex="[0-9]{4}[123][A-Z]{4}[0-9]{4}[A-Z]"),
            validators.MinLengthValidator(limit_value=14),
        ),
    )
    audit_permitted_code = models.PositiveIntegerField(blank=True, default=0)
    exam_credit_flag = models.BooleanField(default=True)
    course = models.ForeignKey(
        "myapp.Course",
        related_name="course_terms",
        on_delete=models.CASCADE,
        null=True,
        default=None,
    )

    class Meta:
        ordering = ["term_identifier"]

    def __str__(self):
        return "%s,%s,%s" % (
            self.id,
            self.term_identifier,
            self.course.course_identifier if self.course else "NONE",
        )

term_identifier = models.CharField(max_length=14, unique=True, validators=(validators.RegexValidator(regex='[0-9]{4}[123][A-Z]{4}[0-9]{4}[A-Z]'), validators.MinLengthValidator(limit_value=14))) class-attribute instance-attribute

audit_permitted_code = models.PositiveIntegerField(blank=True, default=0) class-attribute instance-attribute

exam_credit_flag = models.BooleanField(default=True) class-attribute instance-attribute

course = models.ForeignKey('myapp.Course', related_name='course_terms', on_delete=(models.CASCADE), null=True, default=None) class-attribute instance-attribute

Meta

Source code in myapp/models.py
112
113
class Meta:
    ordering = ["term_identifier"]
ordering = ['term_identifier'] class-attribute instance-attribute

__str__()

Source code in myapp/models.py
115
116
117
118
119
120
def __str__(self):
    return "%s,%s,%s" % (
        self.id,
        self.term_identifier,
        self.course.course_identifier if self.course else "NONE",
    )

Person

Bases: CommonModel

A person.

Source code in myapp/models.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
class Person(CommonModel):
    """
    A person.
    """

    # 'name' is a reserved word in SQL server so just force the db_column name to be different.
    # TODO: This might be a django-pyodbc-azure bug. Check it.
    name = models.CharField(max_length=100, unique=True)

    class Meta:
        ordering = ["name"]
        verbose_name_plural = "people"

    def __str__(self):
        return "%s,%s" % (self.id, self.name)

name = models.CharField(max_length=100, unique=True) class-attribute instance-attribute

Meta

Source code in myapp/models.py
132
133
134
class Meta:
    ordering = ["name"]
    verbose_name_plural = "people"
ordering = ['name'] class-attribute instance-attribute
verbose_name_plural = 'people' class-attribute instance-attribute

__str__()

Source code in myapp/models.py
136
137
def __str__(self):
    return "%s,%s" % (self.id, self.name)

Instructor

Bases: CommonModel

An instructor.

Source code in myapp/models.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
class Instructor(CommonModel):
    """
    An instructor.
    """

    person = models.OneToOneField(
        "myapp.Person",
        related_name="instructor",
        on_delete=models.CASCADE,
        null=True,
        default=None,
    )
    course_terms = models.ManyToManyField(
        "myapp.CourseTerm", related_name="instructors"
    )

    class Meta:
        ordering = ["id"]

    def __str__(self):
        return "%s" % (self.id)

person = models.OneToOneField('myapp.Person', related_name='instructor', on_delete=(models.CASCADE), null=True, default=None) class-attribute instance-attribute

course_terms = models.ManyToManyField('myapp.CourseTerm', related_name='instructors') class-attribute instance-attribute

Meta

Source code in myapp/models.py
156
157
class Meta:
    ordering = ["id"]
ordering = ['id'] class-attribute instance-attribute

__str__()

Source code in myapp/models.py
159
160
def __str__(self):
    return "%s" % (self.id)

Student

Bases: CommonModel

A student.

Source code in myapp/models.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
class Student(CommonModel):
    """
    A student.
    """

    person = models.OneToOneField(
        "myapp.Person",
        related_name="student",
        on_delete=models.CASCADE,
        null=True,
        default=None,
    )
    #: grades includes all registered classes whether or not they have been completed
    grades = models.ManyToManyField("myapp.Grade", related_name="student")

    class Meta:
        ordering = ["id"]

    def __str__(self):
        return "%s" % (self.id)

person = models.OneToOneField('myapp.Person', related_name='student', on_delete=(models.CASCADE), null=True, default=None) class-attribute instance-attribute

grades = models.ManyToManyField('myapp.Grade', related_name='student') class-attribute instance-attribute

Meta

Source code in myapp/models.py
178
179
class Meta:
    ordering = ["id"]
ordering = ['id'] class-attribute instance-attribute

__str__()

Source code in myapp/models.py
181
182
def __str__(self):
    return "%s" % (self.id)

Grade

Bases: CommonModel

A grade for a CourseTerm instance

Source code in myapp/models.py
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
class Grade(CommonModel):
    """
    A grade for a CourseTerm instance
    """

    person = models.OneToOneField(
        "myapp.Student", on_delete=models.DO_NOTHING, related_name="grade"
    )
    course_term = models.OneToOneField(
        "myapp.CourseTerm", on_delete=models.DO_NOTHING, related_name="grade"
    )
    credits = models.FloatField(help_text="Credits attempted/earned")
    grade_letter = models.CharField(
        max_length=2,
        choices=[(k, k) for k in [None, "A", "B", "C", "D", "F", "P"]],
        default=None,
    )
    grade_value = models.FloatField(
        default=0.0, help_text="grade points (e.g. A is 4.0, F is 0.0)"
    )

    def __str__(self):
        return "%s: %s: %s: %s: %s" % (
            self.id,
            self.person.id,
            self.person.name,
            self.course_term.term_identifier,
            self.grade_letter,
        )

person = models.OneToOneField('myapp.Student', on_delete=(models.DO_NOTHING), related_name='grade') class-attribute instance-attribute

course_term = models.OneToOneField('myapp.CourseTerm', on_delete=(models.DO_NOTHING), related_name='grade') class-attribute instance-attribute

credits = models.FloatField(help_text='Credits attempted/earned') class-attribute instance-attribute

grade_letter = models.CharField(max_length=2, choices=[(k, k) for k in [None, 'A', 'B', 'C', 'D', 'F', 'P']], default=None) class-attribute instance-attribute

grade_value = models.FloatField(default=0.0, help_text='grade points (e.g. A is 4.0, F is 0.0)') class-attribute instance-attribute

__str__()

Source code in myapp/models.py
206
207
208
209
210
211
212
213
def __str__(self):
    return "%s: %s: %s: %s: %s" % (
        self.id,
        self.person.id,
        self.person.name,
        self.course_term.term_identifier,
        self.grade_letter,
    )

NonModel

Bases: CommonModel

Make a concrete model that's not actually got a database under it.

Source code in myapp/models.py
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
class NonModel(CommonModel):
    """
    Make a concrete model that's not actually got a database under it.
    """

    # TODO: Look at a custom model manager.
    class Meta:
        managed = False

    # id = models.CharField(primary_key=True, max_length=5)
    field1 = models.CharField(max_length=20)
    field2 = models.CharField(max_length=20, default="hi")
    field3 = models.CharField(max_length=10, default="there")

    # def __init__(self, id, field1, field2=None):
    #     self.id = id
    #     self.field1 = field1
    #     self.field2 = field2

    def __str__(self):
        return "%s" % (self.id)

field1 = models.CharField(max_length=20) class-attribute instance-attribute

field2 = models.CharField(max_length=20, default='hi') class-attribute instance-attribute

field3 = models.CharField(max_length=10, default='there') class-attribute instance-attribute

Meta

Source code in myapp/models.py
222
223
class Meta:
    managed = False
managed = False class-attribute instance-attribute

__str__()

Source code in myapp/models.py
235
236
def __str__(self):
    return "%s" % (self.id)