Commit c48db0ca authored by Daniel W Bond's avatar Daniel W Bond
Browse files

changed floor and room 'numbers' to character fields with appropriate regex...

changed floor and room 'numbers' to character fields with appropriate regex validation to support Liberty
parent 12f9bf2f
...@@ -4,6 +4,7 @@ from __future__ import absolute_import, print_function ...@@ -4,6 +4,7 @@ from __future__ import absolute_import, print_function
from django.db import models from django.db import models
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.text import slugify from django.utils.text import slugify
from django.core.validators import RegexValidator
# third party imports # third party imports
from model_utils.models import TimeStampedModel from model_utils.models import TimeStampedModel
from randomslugfield import RandomSlugField from randomslugfield import RandomSlugField
...@@ -81,7 +82,8 @@ class Building(TimeStampedModel): ...@@ -81,7 +82,8 @@ class Building(TimeStampedModel):
class Floor(TimeStampedModel): class Floor(TimeStampedModel):
building = models.ForeignKey('Building') building = models.ForeignKey('Building')
number = models.IntegerField() number = models.CharField(max_length=1, # Mason doesn't like tall buildings
validators=[RegexValidator(regex='^[0-9]{1}',)])
slug = RandomSlugField(length=6) slug = RandomSlugField(length=6)
...@@ -117,13 +119,21 @@ class Floor(TimeStampedModel): ...@@ -117,13 +119,21 @@ class Floor(TimeStampedModel):
class Room(TimeStampedModel): class Room(TimeStampedModel):
number = models.IntegerField() number = models.CharField(max_length=5,
validators=[RegexValidator(regex='^[A-Z]?[0-9]{3,4}',)])
floor = models.ForeignKey('Floor') floor = models.ForeignKey('Floor')
slug = RandomSlugField(length=6) slug = RandomSlugField(length=6)
room_num = AutoSlugField(populate_from='number',) # unique_with='floor') room_num = AutoSlugField(populate_from='number',) # unique_with='floor')
def get_wing(self):
if self.number[0].isalpha():
return self.number[0]
else:
return None
def get_absolute_url(self): def get_absolute_url(self):
return reverse('detail_room', kwargs={ return reverse('detail_room', kwargs={
'floor': self.floor.floor_num, 'floor': self.floor.floor_num,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment