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

api work

parent 52624348
No preview for this file type
No preview for this file type
......@@ -17,11 +17,19 @@ class Class(models.Model):
choices=YEAR_IN_SCHOOL_CHOICES,
default=FRESHMAN)
def __str__(self): # __unicode__ on Python 2
return self.year_int
class Building(models.Model):
name = models.CharField(max_length=100)
address = models.ForeignKey('Address')
def __str__(self): # __unicode__ on Python 2
return self.name
def __unicode__(self): # __unicode__ on Python 2
return unicode(self.name)
class Room(models.Model):
number = models.IntegerField()
......@@ -32,8 +40,14 @@ class Room(models.Model):
bedD = models.CharField(max_length=80)
building = models.ForeignKey('Building')
def __str__(self): # __unicode__ on Python 2
return self.building.__str__()+" "+self.number.__str__()
class Address(models.Model):
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
No preview for this file type
......@@ -4,4 +4,7 @@ from api import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^building/(?P<building>.+)/(?P<room_number>\d+)', views.room, name='room'),
url(r'^building/(?P<building>[a-zA-Z]+)', views.building, name='building'),
url(r'^buildings/', views.buildings_list, name='buildings_list'),
)
No preview for this file type
from django.http import HttpResponse
from api.models import Building
# Create your views here.
def index(request):
return HttpResponse("Hello, world. You're at the RoomList index.")
def room(request, room_number):
return HttpResponse("You are looking up room number %s." % room_number)
def buildings_list(request):
building_list = Building.objects.order_by('-name')[:5]
json = '{"buildings":['
for p in building_list:
json += '"'+p.__str__()+'",'
json = json[:-1]+']}'
return HttpResponse(json)
def building(request, building):
return HttpResponse("You are looking up building %s" % building)
def room(request, building, room_number):
return HttpResponse("You are looking up room number %s in %s" % (room_number, building))
No preview for this file type
No preview for this file type
No preview for this file type
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