Created
August 18, 2017 07:27
-
-
Save hassanabidpk/531ab7f20aafb1817ef4cfeeefb35b12 to your computer and use it in GitHub Desktop.
Pycon Lunch Views
This file contains 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
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