mirror of
https://github.com/bspeice/UNCCGameDay-Server
synced 2024-12-04 13:58:14 -05:00
Add new serialization code
This commit is contained in:
parent
269795202d
commit
7be5cd6f97
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,5 +1,8 @@
|
||||
*.pyc
|
||||
*.sqlite
|
||||
*.sublime*
|
||||
bin/
|
||||
include/
|
||||
lib/
|
||||
local/
|
||||
.codeintel/
|
@ -5,7 +5,7 @@ from datetime import datetime
|
||||
# Create your models here.
|
||||
class RegisteredUser(models.Model):
|
||||
|
||||
date_registered = models.DateTimeField()
|
||||
date_registered = models.DateTimeField(default=datetime.now)
|
||||
first_name = models.CharField(max_length=64)
|
||||
last_name = models.CharField(max_length=64)
|
||||
section = models.CharField(max_length=8)
|
||||
@ -46,7 +46,7 @@ class ParkingLot(models.Model):
|
||||
|
||||
# Only one ParkingLot per location
|
||||
location = models.CharField(choices=LOT_CHOICES, unique=True,
|
||||
primary_key=True)
|
||||
primary_key=True, max_length=8)
|
||||
# parkingrating_set
|
||||
|
||||
@property
|
||||
@ -59,8 +59,7 @@ class ParkingLot(models.Model):
|
||||
# Get the current rating of this parking lot
|
||||
NUM_LOTS = 10
|
||||
if self.current_ratings.count() < NUM_LOTS:
|
||||
# Probably raise an exception here, not enough responses yet
|
||||
pass
|
||||
return None
|
||||
else:
|
||||
total = sum([ ParkingRating.RATING_WEIGHTS[r.rating]
|
||||
for r in self.parkingrating_set.all().order_by('created')[0:10] ])
|
||||
@ -86,5 +85,5 @@ class ParkingRating(models.Model):
|
||||
}
|
||||
|
||||
rating = models.CharField(max_length=10, choices=RATING_CHOICES)
|
||||
created = models.DateTimeField(default=datetime.datetime.now)
|
||||
created = models.DateTimeField(default=datetime.now)
|
||||
parking_lot = models.ForeignKey(ParkingLot)
|
||||
|
10
uncc_gameday/gameday/serializers.py
Normal file
10
uncc_gameday/gameday/serializers.py
Normal file
@ -0,0 +1,10 @@
|
||||
from django.forms import widgets
|
||||
from rest_framework import serializers
|
||||
from models import *
|
||||
|
||||
class ParkingLotSerializer(serializers.ModelSerializer):
|
||||
filled_pct = serializers.IntegerField(read_only=True, source='get_rating')
|
||||
|
||||
class Meta:
|
||||
model = ParkingLot
|
||||
fields = ('location', 'filled_pct')
|
6
uncc_gameday/gameday/urls.py
Normal file
6
uncc_gameday/gameday/urls.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.conf.urls import url, patterns
|
||||
import views
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url('^lots/$', views.ParkingLotList.as_view())
|
||||
)
|
@ -1 +1,15 @@
|
||||
# Create your views here.
|
||||
from models import ParkingLot
|
||||
from serializers import ParkingLotSerializer
|
||||
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
|
||||
class ParkingLotList(APIView):
|
||||
"""
|
||||
List all parking lots
|
||||
"""
|
||||
|
||||
def get(self, request):
|
||||
parking_lots = ParkingLot.objects.all()
|
||||
serializer = ParkingLotSerializer(parking_lots, many=True)
|
||||
return Response(serializer.data)
|
7
uncc_gameday/uncc_gameday/one_shot.py
Normal file
7
uncc_gameday/uncc_gameday/one_shot.py
Normal file
@ -0,0 +1,7 @@
|
||||
# Any code below will be run exactly once on import.
|
||||
# Basically, we run whenever the root URLconf is loaded.
|
||||
|
||||
from gameday.models import ParkingLot
|
||||
if ParkingLot.objects.all().count() == 0:
|
||||
for location in ParkingLot.LOT_CHOICES:
|
||||
ParkingLot.objects.create(location=location)
|
@ -119,12 +119,14 @@ INSTALLED_APPS = (
|
||||
#'django.contrib.sessions',
|
||||
#'django.contrib.sites',
|
||||
#'django.contrib.messages',
|
||||
#'django.contrib.staticfiles',
|
||||
'django.contrib.staticfiles',
|
||||
# Uncomment the next line to enable the admin:
|
||||
# 'django.contrib.admin',
|
||||
# Uncomment the next line to enable admin documentation:
|
||||
# 'django.contrib.admindocs',
|
||||
'rest_framework',
|
||||
|
||||
'gameday',
|
||||
)
|
||||
|
||||
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
|
||||
|
@ -1,5 +1,8 @@
|
||||
from django.conf.urls import patterns, include, url
|
||||
|
||||
# Bit of a hack, but run any one-time code
|
||||
import one_shot
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
# from django.contrib import admin
|
||||
# admin.autodiscover()
|
||||
|
Loading…
Reference in New Issue
Block a user