models.py 3.21 KB
Newer Older
1
# core django imports
2
from django.db import models
3
from django.core.urlresolvers import reverse
4
from django.utils.text import slugify
5
# third party imports
Daniel W Bond's avatar
Daniel W Bond committed
6
from model_utils.models import TimeStampedModel
7
from randomslugfield import RandomSlugField
8
from autoslug import AutoSlugField
Daniel W Bond's avatar
Daniel W Bond committed
9

10

Daniel W Bond's avatar
Daniel W Bond committed
11
class Building(TimeStampedModel):
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,
Daniel W Bond's avatar
Daniel W Bond committed
26 27 28
                                     default=NONE)

    # address = models.ForeignKey('Address')
29 30 31 32 33 34 35

    PRINCE_WILLIAM = 'pw'
    MASONVALE = 'mv'
    FAIRFAX = 'ff'
    CAMPUS_CHOICES = (
        (NONE, 'None'),
        (PRINCE_WILLIAM, 'Prince William'),
Daniel W Bond's avatar
Daniel W Bond committed
36
        (MASONVALE, 'MasonVale'),
37 38 39
        (FAIRFAX, 'Fairfax'),
    )

40
    campus = models.CharField(max_length=100, choices=CAMPUS_CHOICES, default='ff')
41

42 43
    slug = RandomSlugField(length=6)
    building_name = AutoSlugField(populate_from='name')
Daniel W Bond's avatar
Daniel W Bond committed
44

Daniel W Bond's avatar
Daniel W Bond committed
45
    def get_absolute_url(self):
46
        return reverse('detail_building', kwargs={
47
            'building': slugify(self.building_name),
Daniel W Bond's avatar
Daniel W Bond committed
48
            'slug': self.slug,
49
        })
Daniel W Bond's avatar
Daniel W Bond committed
50

Daniel W Bond's avatar
Daniel W Bond committed
51
    def __str__(self):  # __unicode__ on Python 2
52
        return self.name
Daniel W Bond's avatar
Daniel W Bond committed
53 54

    def __unicode__(self):  # __unicode__ on Python 2
55
        return unicode(self.name)
Daniel W Bond's avatar
Daniel W Bond committed
56

Daniel W Bond's avatar
Daniel W Bond committed
57 58
    class Meta:
        ordering = ['name']
59

Daniel W Bond's avatar
Daniel W Bond committed
60

Daniel W Bond's avatar
Daniel W Bond committed
61 62 63 64
class Floor(TimeStampedModel):
    building = models.ForeignKey('Building')
    number = models.IntegerField()

65 66
    slug = RandomSlugField(length=6)

Daniel W Bond's avatar
Daniel W Bond committed
67
    floor_num = AutoSlugField(populate_from='number',)  # unique_with='building')
Daniel W Bond's avatar
Daniel W Bond committed
68

Daniel W Bond's avatar
Daniel W Bond committed
69 70
    def get_absolute_url(self):
        return reverse('detail_floor', kwargs={
71
            'building': slugify(self.building.building_name),
Daniel W Bond's avatar
Daniel W Bond committed
72 73
            'floor': self.floor_num,
            'slug': self.slug,
Daniel W Bond's avatar
Daniel W Bond committed
74 75
        })

Daniel W Bond's avatar
Daniel W Bond committed
76
    def __str__(self):  # __unicode__ on Python 2
Daniel W Bond's avatar
Daniel W Bond committed
77 78
        return self.building.__str__()+" "+self.number.__str__()

Daniel W Bond's avatar
Daniel W Bond committed
79
    class Meta:
80
        ordering = ['building', 'number']
Daniel W Bond's avatar
Daniel W Bond committed
81

Daniel W Bond's avatar
Daniel W Bond committed
82

Daniel W Bond's avatar
Daniel W Bond committed
83
class Room(TimeStampedModel):
84
    number = models.IntegerField()
Daniel W Bond's avatar
Daniel W Bond committed
85
    floor = models.ForeignKey('Floor')
86

87 88
    slug = RandomSlugField(length=6)

Daniel W Bond's avatar
Daniel W Bond committed
89
    room_num = AutoSlugField(populate_from='number',)  # unique_with='floor')
Daniel W Bond's avatar
Daniel W Bond committed
90

Daniel W Bond's avatar
Daniel W Bond committed
91 92
    def get_absolute_url(self):
        return reverse('detail_room', kwargs={
Daniel W Bond's avatar
Daniel W Bond committed
93
            'floor': self.floor.floor_num,
94
            'building': slugify(self.floor.building.building_name),
Daniel W Bond's avatar
Daniel W Bond committed
95 96
            'room': self.room_num,
            'slug': self.slug,
Daniel W Bond's avatar
Daniel W Bond committed
97 98
        })

Daniel W Bond's avatar
Daniel W Bond committed
99
    def __str__(self):  # __unicode__ on Python 2
Daniel W Bond's avatar
Daniel W Bond committed
100
        return self.floor.building.__str__()+" "+self.number.__str__()
101

Daniel W Bond's avatar
Daniel W Bond committed
102 103 104
    class Meta:
        ordering = ['number']

Daniel W Bond's avatar
Daniel W Bond committed
105

106 107
# buildings on campus don't have separate addresses yet
#class Address(TimeStampedModel):
Daniel W Bond's avatar
Daniel W Bond committed
108

109 110 111 112
#    street = models.CharField(max_length=120)
#    city = models.CharField(max_length=120)
#    state = USStateField()
#    zip_code = models.IntegerField(max_length=5)
113

Daniel W Bond's avatar
Daniel W Bond committed
114
#    class Meta:
115
#        verbose_name_plural = 'addresses'
Daniel W Bond's avatar
Daniel W Bond committed
116

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