models.py 1.15 KB
Newer Older
1
# core django imports
2
from django.db import models
Daniel W Bond's avatar
Daniel W Bond committed
3
from django.contrib.auth.models import User
Daniel W Bond's avatar
Daniel W Bond committed
4
#from django.core.validators import RegexValidator
Daniel W Bond's avatar
Daniel W Bond committed
5
from django.core.urlresolvers import reverse
6
7
8
# third-party imports
from autoslug import AutoSlugField
from model_utils.models import TimeStampedModel
9

Daniel W Bond's avatar
Daniel W Bond committed
10

11
12
class Student(TimeStampedModel):
    # django user includes username, password, first name, and last name
13
    user = models.OneToOneField(User)
14

Daniel W Bond's avatar
Daniel W Bond committed
15
    slug = AutoSlugField(populate_from='user', unique=True)
16

17
18
    emails_sent = models.PositiveIntegerField(default=0)

Daniel W Bond's avatar
Daniel W Bond committed
19
    def get_absolute_url(self):
Daniel W Bond's avatar
Daniel W Bond committed
20
        return reverse('profile', kwargs={'slug': self.slug})
Daniel W Bond's avatar
Daniel W Bond committed
21

22
23
    def __unicode__(self):
        return '%s' % self.user.username
24

Daniel W Bond's avatar
Daniel W Bond committed
25

26
class Course(TimeStampedModel):
Daniel W Bond's avatar
Daniel W Bond committed
27
28
29
    name = models.CharField(max_length=255)
    department = models.CharField(max_length=255)
    departmentAbbreviation = models.CharField(max_length=4)
Daniel W Bond's avatar
Daniel W Bond committed
30
31
    # number = models.CharField(max_length=255,
                              # validators=RegexValidator('[0-9]{3,}'))
Daniel W Bond's avatar
Daniel W Bond committed
32
33
34
35
    number = models.CharField(max_length=3)

    def __unicode__(self):
        return "%s %s" % (self.departmentAbbreviation, self.number)