models.py 1.09 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
5
from model_utils.models import TimeStampedModel
from django.core.validators import RegexValidator
Daniel W Bond's avatar
Daniel W Bond committed
6
from django.core.urlresolvers import reverse
7

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

# implement ratings later
#    rating = models.IntegerField(null=True,default=0)
14

15
    slug = AutoSlugField(populate_from = 'user', unique = True)
16

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

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

23
class Course(TimeStampedModel):
24
25
26
	name = models.CharField(max_length = 255)
	department = models.CharField(max_length = 255)
        departmentAbbreviation = models.CharField(max_length = 4)
27
	#number = models.CharField(max_length=255, validators=RegexValidator('[0-9]{3,}'))
28
	number = models.CharField(max_length = 3)
29
30

	def __unicode__(self):
Daniel W Bond's avatar
Daniel W Bond committed
31
		return "%s %s" % (self.departmentAbbreviation, self.number)