Commit be0c2af4 authored by Jason D Yeomans's avatar Jason D Yeomans
Browse files

Added Building api query, lists rooms and info

parent fbc89840
......@@ -35,9 +35,9 @@ class Room(models.Model):
number = models.IntegerField()
floor = models.IntegerField()
bedA = models.CharField(max_length=80)
bedB = models.CharField(max_length=80)
bedC = models.CharField(max_length=80)
bedD = 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')
def __str__(self): # __unicode__ on Python 2
......@@ -5,6 +5,6 @@ from api import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^building/(?P<building>.+)/(?P<room_number>\d+)$',, name='room'),
url(r'^building/(?P<building>[a-zA-Z]+)$', views.building, name='building'),
url(r'^building/(?P<buildingName>[a-zA-Z]+)$', views.building, name='building'),
url(r'^buildings/$', views.buildings_list, name='buildings_list'),
from django.http import HttpResponse
from api.models import Building
from api.models import Building, Room
# Create your views here.
def index(request):
......@@ -14,8 +14,21 @@ def buildings_list(request):
json = json[:-1]+']}'
return HttpResponse(json)
def building(request, building):
return HttpResponse("You are looking up building %s" % building)
def building(request, buildingName):
room_list = Room.objects.filter(building__name=""+buildingName)
json = '{"'+buildingName+'":['
for p in room_list:
json += '"'+p.number.__str__()+'":['
json += '"floor":'+p.floor.__str__()+',"bedA":"'+p.bedA.__str__()+'"'
if p.bedB.__str__() is not '':
json += ',"bedB":"'+p.bedB.__str__()+'"'
if p.bedC.__str__() is not '':
json += ',"bedC":"'+p.bedC.__str__()+'"'
if p.bedD.__str__() is not '':
json += ',"bedD":"'+p.bedD.__str__()+'"'
json += '],'
json = json[:-1]+']}'
return HttpResponse(json)
def room(request, building, room_number):
return HttpResponse("You are looking up room number %s in %s" % (room_number, building))
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