Commit 40b449e8 authored by Ben Waters's avatar Ben Waters
Browse files

Update on models

parent d249e696
from django.shortcuts import render
from rest_framework import viewsets
from rest_framework import authentication, permissions
from rest_framework.response import Response
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.decorators import detail_route
from .models import Location, LocationSerializer, UserLocation, UserLocationSerializer
from .models import Location, LocationSerializer
# Create your views here.
class LocationViewSet(viewsets.ModelViewSet):
class LocationViewSet(viewsets.ModelViewSet):
queryset = Location.objects.all()
serializer_class = LocationSerializer
@api_view(['PUT'])
def location_find(request, minLon, maxLon, minLat, maxLat):
if request.method == 'POST':
@detail_route(methods=['post'])
def get_location(self,request,pk=None):
location = self.get_object()
serializer = LocationSerializer(data=request.DATA)
if serializer.is_valid():
return Response(serializer.data, status=status.HTTP_200_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
lat = serializer.data['lat']
long = serializer.data['long']
location = Location.objects.filter()
out_serializer = LocationSerializer(location)
return Response(out_serializer.data)
else:
return Response(serializer.errors,
status=status.HTTP_400_BAD_REQUEST)
class UserLocationViewSet(viewsets.ModelViewSet):
queryset = UserLocation.objects.all()
serializer_class = UserLocationSerializer
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