Python rest_framework.parsers.JSONParser() Examples

The following are 30 code examples for showing how to use rest_framework.parsers.JSONParser(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module rest_framework.parsers , or try the search function .

Example 1
Project: ansible-mezzanine   Author: keithadavidson   File: views.py    License: MIT License 6 votes vote down vote up
def snippet_list(request):
    """
    List all code snippets, or create a new snippet.
    """
    if request.method == 'GET':
        snippets = Snippet.objects.all()
        serializer = SnippetSerializer(snippets, many=True)
        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = SnippetSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400) 
Example 2
Project: ansible-mezzanine   Author: keithadavidson   File: views.py    License: MIT License 6 votes vote down vote up
def snippet_detail(request, pk):
    """
    Retrieve, update or delete a code snippet.
    """
    try:
        snippet = Snippet.objects.get(pk=pk)
    except Snippet.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = SnippetSerializer(snippet)
        return JSONResponse(serializer.data)

    elif request.method == 'PUT':
        data = JSONParser().parse(request)
        serializer = SnippetSerializer(snippet, data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data)
        return JSONResponse(serializer.errors, status=400)

    elif request.method == 'DELETE':
        snippet.delete()
        return HttpResponse(status=204) 
Example 3
Project: Django-RESTful-Web-Services   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def toy_detail(request, pk):
    try:
        toy = Toy.objects.get(pk=pk)
    except Toy.DoesNotExist:
        return HttpResponse(status=status.HTTP_404_NOT_FOUND)
    if request.method == 'GET':
        toy_serializer = ToySerializer(toy)
        return JSONResponse(toy_serializer.data)
    elif request.method == 'PUT':
        toy_data = JSONParser().parse(request)
        toy_serializer = ToySerializer(toy, data=toy_data)
        if toy_serializer.is_valid():
            toy_serializer.save()
            return JSONResponse(toy_serializer.data)
        return JSONResponse(toy_serializer.errors, \
            status=status.HTTP_400_BAD_REQUEST)
    elif request.method == 'DELETE':
        toy.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 4
Project: Django-RESTful-Web-Services   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def toy_detail(request, pk):
    try:
        toy = Toy.objects.get(pk=pk)
    except Toy.DoesNotExist:
        return HttpResponse(status=status.HTTP_404_NOT_FOUND)
    if request.method == 'GET':
        toy_serializer = ToySerializer(toy)
        return JSONResponse(toy_serializer.data)
    elif request.method == 'PUT':
        toy_data = JSONParser().parse(request)
        toy_serializer = ToySerializer(toy, data=toy_data)
        if toy_serializer.is_valid():
            toy_serializer.save()
            return JSONResponse(toy_serializer.data)
        return JSONResponse(toy_serializer.errors, \
            status=status.HTTP_400_BAD_REQUEST)
    elif request.method == 'DELETE':
        toy.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 5
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        print(schedules_serializer.data)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parse(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 6
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_detail(request, pk):
    try:
        schedule = Schedule.objects.get(pk=pk)
    except Schedule.DoesNotExist:
        return HttpResponse(status=status.HTTP_404_NOT_FOUND)
    
    #Retrive one record
    if request.method == 'GET':
        schedule_serializer = ScheduleSerializer(schedule)
        print(schedule_serializer.data)
        return JsonResponse(schedule_serializer.data,safe=False)

    #Update one record
    if request.method == 'PUT':
        schedule_data = JSONParser().parse(request)
        schedule_serializer = ScheduleSerializer(schedule, data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data,safe=False)  
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)

    #Delete one record
    if request.method == 'DELETE':
        schedule.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 7
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 8
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_detail(request, pk):
    try:
        schedule = Schedule.objects.get(pk=pk)
    except Schedule.DoesNotExist:
        return HttpResponse(status=status.HTTP_404_NOT_FOUND)
    
    #Retrive one record
    if request.method == 'GET':
        schedule_serializer = ScheduleSerializer(schedule)
        return JsonResponse(schedule_serializer.data)

    #Update one record
    if request.method == 'PUT':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(schedule, data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)

    #Delete one record
    if request.method == 'DLETE':
        schedule.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 9
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 10
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 11
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_detail(request, pk):
    try:
        schedule = Schedule.objects.get(pk=pk)
    except Schedule.DoesNotExist:
        return HttpResponse(status=status.HTTP_404_NOT_FOUND)
    
    #Retrive one record
    if request.method == 'GET':
        schedule_serializer = ScheduleSerializer(schedule)
        return JsonResponse(schedule_serializer.data)

    #Update one record
    if request.method == 'PUT':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(schedule, data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)

    #Delete one record
    if request.method == 'DLETE':
        schedule.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 12
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 13
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_detail(request, pk):
    try:
        schedule = Schedule.objects.get(pk=pk)
    except Schedule.DoesNotExist:
        return HttpResponse(status=status.HTTP_404_NOT_FOUND)
    
    #Retrive one record
    if request.method == 'GET':
        schedule_serializer = ScheduleSerializer(schedule)
        return JsonResponse(schedule_serializer.data)

    #Update one record
    if request.method == 'PUT':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(schedule, data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)

    #Delete one record
    if request.method == 'DLETE':
        schedule.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 14
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 15
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 16
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_detail(request, pk):
    try:
        schedule = Schedule.objects.get(pk=pk)
    except Schedule.DoesNotExist:
        return HttpResponse(status=status.HTTP_404_NOT_FOUND)
    
    #Retrive one record
    if request.method == 'GET':
        schedule_serializer = ScheduleSerializer(schedule)
        return JsonResponse(schedule_serializer.data)

    #Update one record
    if request.method == 'PUT':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(schedule, data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)

    #Delete one record
    if request.method == 'DLETE':
        schedule.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 17
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 18
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_detail(request, pk):
    try:
        schedule = Schedule.objects.get(pk=pk)
    except Schedule.DoesNotExist:
        return HttpResponse(status=status.HTTP_404_NOT_FOUND)
    
    #Retrive one record
    if request.method == 'GET':
        schedule_serializer = ScheduleSerializer(schedule)
        return JsonResponse(schedule_serializer.data)

    #Update one record
    if request.method == 'PUT':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(schedule, data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)

    #Delete one record
    if request.method == 'DLETE':
        schedule.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 19
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 20
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 21
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_detail(request, pk):
    try:
        schedule = Schedule.objects.get(pk=pk)
    except Schedule.DoesNotExist:
        return HttpResponse(status=status.HTTP_404_NOT_FOUND)
    
    #Retrive one record
    if request.method == 'GET':
        schedule_serializer = ScheduleSerializer(schedule)
        return JsonResponse(schedule_serializer.data)

    #Update one record
    if request.method == 'PUT':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(schedule, data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)

    #Delete one record
    if request.method == 'DLETE':
        schedule.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 22
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 23
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_detail(request, pk):
    try:
        schedule = Schedule.objects.get(pk=pk)
    except Schedule.DoesNotExist:
        return HttpResponse(status=status.HTTP_404_NOT_FOUND)
    
    #Retrive one record
    if request.method == 'GET':
        schedule_serializer = ScheduleSerializer(schedule)
        return JsonResponse(schedule_serializer.data)

    #Update one record
    if request.method == 'PUT':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(schedule, data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)

    #Delete one record
    if request.method == 'DLETE':
        schedule.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 24
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 25
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 26
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_detail(request, pk):
    try:
        schedule = Schedule.objects.get(pk=pk)
    except Schedule.DoesNotExist:
        return HttpResponse(status=status.HTTP_404_NOT_FOUND)
    
    #Retrive one record
    if request.method == 'GET':
        schedule_serializer = ScheduleSerializer(schedule)
        return JsonResponse(schedule_serializer.data)

    #Update one record
    if request.method == 'PUT':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(schedule, data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)

    #Delete one record
    if request.method == 'DLETE':
        schedule.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 27
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 28
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_detail(request, pk):
    try:
        schedule = Schedule.objects.get(pk=pk)
    except Schedule.DoesNotExist:
        return HttpResponse(status=status.HTTP_404_NOT_FOUND)
    
    #Retrive one record
    if request.method == 'GET':
        schedule_serializer = ScheduleSerializer(schedule)
        return JsonResponse(schedule_serializer.data)

    #Update one record
    if request.method == 'PUT':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(schedule, data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)

    #Delete one record
    if request.method == 'DLETE':
        schedule.delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 29
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT) 
Example 30
Project: -Full-Stack-Web-Development-with-Django-2.x-and-Angular-8   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def flight_list(request):
    #Get all
    if request.method == 'GET':
        schedules = Schedule.objects.all()
        schedules_serializer = ScheduleSerializer(schedules,many=True)
        return JsonResponse(schedules_serializer.data, safe=False)
    
    #Add one
    if request.method == 'POST':
        schedule_data = JSONParser().parser(request)
        schedule_serializer = ScheduleSerializer(data=schedule_data)
        if schedule_serializer.is_valid():
            schedule_serializer.save()
            return JsonResponse(schedule_serializer.data, status=status.HTTP_201_CREATED)
        return JsonResponse(schedule_serializer.errors,status=status.HTTP_400_BAD_REQUEST)
    
    #Delete All
    if request.method == 'DELETE':
        Schedule.objects.all().delete()
        return HttpResponse(status=status.HTTP_204_NO_CONTENT)