Skip to content

Instantly share code, notes, and snippets.

@hassanabidpk
Created August 18, 2017 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hassanabidpk/531ab7f20aafb1817ef4cfeeefb35b12 to your computer and use it in GitHub Desktop.
Save hassanabidpk/531ab7f20aafb1817ef4cfeeefb35b12 to your computer and use it in GitHub Desktop.
Pycon Lunch Views
from django.shortcuts import render
from django.http import JsonResponse
from .models import Restaurant
from .serializers import RestaurantSerializer
from django.views.decorators.csrf import csrf_exempt
def index(request):
rest_list = Restaurant.objects.order_by('-pub_date')
context = {'rest_list': rest_list}
return render(request, 'food/index.html', context)
# Rest api end point
def get_rest_list(request):
"""
Returns Json list of all restaurants
"""
if request.method == "GET":
rest_list = Restaurant.objects.order_by('-pub_date')
serializer = RestaurantSerializer(rest_list, many=True)
return JsonResponse(serializer.data, safe=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment