models.py 2.4 KB
Newer Older
1
from django.db import models
Daniel W Bond's avatar
Daniel W Bond committed
2 3 4
from autoslug import AutoSlugField
from model_utils.models import TimeStampedModel

5 6
from django.contrib.auth.models import User

7 8
from localflavor.us.models import USStateField

Daniel W Bond's avatar
Daniel W Bond committed
9
class Building(TimeStampedModel):
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
    name = models.CharField(max_length=100)

    NONE = 'na'
    AQUIA = 'aq'
    RAPPAHANNOCK = 'ra'
    SHENANDOAH = 'sh'
    NEIGHBOURHOOD_CHOICES = (
        (NONE, 'None'),
        (AQUIA, 'Aquia'),
        (RAPPAHANNOCK, 'Rappahannock'),
        (SHENANDOAH, 'Shenandoah'),
    )

    neighbourhood = models.CharField(max_length=100, choices=NEIGHBOURHOOD_CHOICES,
    default=NONE)
    address = models.ForeignKey('Address')

Daniel W Bond's avatar
Daniel W Bond committed
27 28
    slug = AutoSlugField(populate_from='name', unique=True)

29 30 31 32 33
    def __str__(self):              # __unicode__ on Python 2
        return self.name
    def __unicode__(self):              # __unicode__ on Python 2
        return unicode(self.name)

Daniel W Bond's avatar
Daniel W Bond committed
34
class Room(TimeStampedModel):
35 36 37 38 39 40 41 42
    number = models.IntegerField()
    floor = models.IntegerField()
    bedA = models.CharField(max_length=80)
    bedB = models.CharField(max_length=80, blank=True)
    bedC = models.CharField(max_length=80, blank=True)
    bedD = models.CharField(max_length=80, blank=True)
    building = models.ForeignKey('Building')

Daniel W Bond's avatar
Daniel W Bond committed
43 44
    slug = AutoSlugField(populate_from='number', unique=True)

45 46 47
    def __str__(self):              # __unicode__ on Python 2
        return self.building.__str__()+" "+self.number.__str__()

Daniel W Bond's avatar
Daniel W Bond committed
48
class Address(TimeStampedModel):
Daniel W Bond's avatar
Daniel W Bond committed
49 50 51
    
    street = models.CharField(max_length=120)
    city = models.CharField(max_length=120)
52
    state = USStateField()
Daniel W Bond's avatar
Daniel W Bond committed
53
    zip_code = models.IntegerField(max_length=5)
54

Daniel W Bond's avatar
Daniel W Bond committed
55 56 57
    class Meta: 
        verbose_name_plural = 'addresses'

58 59
    def __str__(self):              # __unicode__ on Python 2
        return self.street
60

Daniel W Bond's avatar
Daniel W Bond committed
61
class Class(TimeStampedModel):
62 63 64 65 66 67 68 69 70 71 72 73 74 75
    year_int = models.IntegerField()
    FRESHMAN = 'FR'
    SOPHOMORE = 'SO'
    JUNIOR = 'JR'
    SENIOR = 'SR'
    YEAR_IN_SCHOOL_CHOICES = (
        (FRESHMAN, 'Freshman'),
        (SOPHOMORE, 'Sophomore'),
        (JUNIOR, 'Junior'),
        (SENIOR, 'Senior'),
    )
    year_in_school = models.CharField(max_length=2,
                                      choices=YEAR_IN_SCHOOL_CHOICES,
                                      default=FRESHMAN)
Daniel W Bond's avatar
Daniel W Bond committed
76 77 78
    class Meta: 
        verbose_name_plural = 'classes'

79
    def __str__(self):              # __unicode__ on Python 2
80
        return str(self.year_int)