Created
April 16, 2016 09:18
-
-
Save hassanabidpk/597bdb43d4e15f9828356cdb759c1bba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# required imports | |
def getRestaurantList(ilocation,query): | |
#.... | |
# code implementation can be seen here https://github.com/hassanabidpk/searchrestaurant/blob/master/django/searchrestaurant/search/views.py | |
return result | |
class RestaurantList(APIView): | |
def get(self,request,format=None): | |
if "location" in request.GET and "rtype" in request.GET: | |
location = request.GET["location"] | |
location = location.replace(" ","+") | |
restaurantType = request.GET["rtype"] | |
else: | |
restaurants = Restaurant.objects.all() | |
serializer = RestaurantSerializer(restaurants, many=True) | |
return Response(serializer.data,status=status.HTTP_200_OK) | |
try: | |
loc = Location.objects.get(restaurant_location=location,restaurant_type=restaurantType) | |
restaurants = loc.restaurant.all() | |
serializer = RestaurantSerializer(restaurants, many=True) | |
return Response(serializer.data,status=status.HTTP_200_OK) | |
except MultipleObjectsReturned: | |
loc = loc[0] | |
restaurants = loc.restaurant.all() | |
serializer = RestaurantSerializer(restaurants, many=True) | |
return Response(serializer.data,status=status.HTTP_200_OK) | |
except ObjectDoesNotExist: | |
context = getRestaurantList(location,restaurantType) | |
try: | |
loc = Location.objects.get(restaurant_location=location,restaurant_type=restaurantType) | |
restaurants = loc.restaurant.all() | |
serializer = RestaurantSerializer(restaurants, many=True) | |
return Response(serializer.data,status=status.HTTP_200_OK) | |
except ObjectDoesNotExist: | |
print ("does not exist") | |
return Response(data={'error':"not-found",'status':"404"},status=status.HTTP_404_NOT_FOUND) | |
except MultipleObjectsReturned: | |
loc = loc[0] | |
restaurants = loc.restaurant.all() | |
serializer = RestaurantSerializer(restaurants, many=True) | |
return Response(serializer.data,status=status.HTTP_200_OK) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment