diff --git a/uncc_gameday/gameday/serializers.py b/uncc_gameday/gameday/serializers.py index 53593cc..058aaf8 100644 --- a/uncc_gameday/gameday/serializers.py +++ b/uncc_gameday/gameday/serializers.py @@ -7,4 +7,9 @@ class ParkingLotSerializer(serializers.ModelSerializer): class Meta: model = ParkingLot - fields = ('location', 'filled_pct') \ No newline at end of file + fields = ('location', 'filled_pct') + +class ParkingRatingSerializer(serializers.ModelSerializer): + class Meta: + model = ParkingRating + fields = ('rating', 'parking_lot',) diff --git a/uncc_gameday/gameday/urls.py b/uncc_gameday/gameday/urls.py index c021d93..e48a2b4 100644 --- a/uncc_gameday/gameday/urls.py +++ b/uncc_gameday/gameday/urls.py @@ -2,5 +2,6 @@ from django.conf.urls import url, patterns import views urlpatterns = patterns('', - url('^lots/$', views.ParkingLotList.as_view()) + url('^lots/$', views.ParkingLotList.as_view()), + url('^rate/$', views.RateLot.as_view()) ) \ No newline at end of file diff --git a/uncc_gameday/gameday/views.py b/uncc_gameday/gameday/views.py index 4364652..da6d710 100755 --- a/uncc_gameday/gameday/views.py +++ b/uncc_gameday/gameday/views.py @@ -1,8 +1,9 @@ -from models import ParkingLot -from serializers import ParkingLotSerializer +from models import ParkingLot, ParkingRating +from serializers import * from rest_framework.views import APIView from rest_framework.response import Response +from rest_framework import status class ParkingLotList(APIView): """ @@ -12,4 +13,16 @@ class ParkingLotList(APIView): def get(self, request): parking_lots = ParkingLot.objects.all() serializer = ParkingLotSerializer(parking_lots, many=True) - return Response(serializer.data) \ No newline at end of file + return Response(serializer.data) + +class RateLot(APIView): + """ + Rate a parking lot + """ + + def post(self, request): + rating = ParkingRatingSerializer(data=request.DATA) + if rating.is_valid(): + rating.save() + return Response(rating.data) + return Response(rating.errors, status=status.HTTP_400_BAD_REQUEST) \ No newline at end of file diff --git a/uncc_gameday/uncc_gameday/one_shot.py b/uncc_gameday/uncc_gameday/one_shot.py index d6e03e8..37b0713 100644 --- a/uncc_gameday/uncc_gameday/one_shot.py +++ b/uncc_gameday/uncc_gameday/one_shot.py @@ -4,4 +4,4 @@ from gameday.models import ParkingLot if ParkingLot.objects.all().count() == 0: for location in ParkingLot.LOT_CHOICES: - ParkingLot.objects.create(location=location) \ No newline at end of file + ParkingLot.objects.create(location=location[0]) \ No newline at end of file