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

Daniel W Bond's avatar
Daniel W Bond committed
8

9
class Student(TimeStampedModel):
10
    user = models.OneToOneField(User)
11
    # django user includes username, password, first name, and last name
Daniel W Bond's avatar
Daniel W Bond committed
12

Daniel W Bond's avatar
Daniel W Bond committed
13
14
    # implement ratings later
    #rating = models.IntegerField(null=True, default=0)
15

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

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

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

Daniel W Bond's avatar
Daniel W Bond committed
24

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

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