models.py 2.64 KB
Newer Older
1
2
from django.db import models

Daniel W Bond's avatar
Daniel W Bond committed
3
4
5
from autoslug import AutoSlugField
from model_utils.models import TimeStampedModel

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

Daniel W Bond's avatar
Daniel W Bond committed
8
class Building(TimeStampedModel):
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    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
26
27
    slug = AutoSlugField(populate_from='name', unique=True)

28
29
30
31
32
    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
33
class Room(TimeStampedModel):
34
35
36
37
38
39
40
41
    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
42
43
    slug = AutoSlugField(populate_from='number', unique=True)

44
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):
49
50
51
52
53
54
    street = models.CharField(max_length=100)
    zip_code = models.IntegerField(max_length=5)
    state = models.CharField(max_length=2)

    def __str__(self):              # __unicode__ on Python 2
        return self.street
55

Jason D Yeomans's avatar
Jason D Yeomans committed
56

Daniel W Bond's avatar
Daniel W Bond committed
57
class Class(TimeStampedModel):
58
59
60
61
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)

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

Jason D Yeomans's avatar
Jason D Yeomans committed
76

Daniel W Bond's avatar
Daniel W Bond committed
77
class Student(TimeStampedModel):
78
79
80
81
    user = models.OneToOneField(User)
    # Django user includes a username, password, email, first name, and last name
    room = models.OneToOneField(Room)
    # class = models.OneToOneField(Class)
Daniel W Bond's avatar
Daniel W Bond committed
82

Daniel W Bond's avatar
Daniel W Bond committed
83
84
85
86
    # major = models.

    # social media accounts

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

Jason D Yeomans's avatar
Jason D Yeomans committed
89
90
    def __str__(self):              # __unicode__ on Python 2
        return self.user.username