Skip to content

Instantly share code, notes, and snippets.

@mansha99
Created July 4, 2023 17:38
Show Gist options
  • Save mansha99/d11958e9cfa5c56c955810ee4c411e14 to your computer and use it in GitHub Desktop.
Save mansha99/d11958e9cfa5c56c955810ee4c411e14 to your computer and use it in GitHub Desktop.
notice_app/notices/views/notice.py
from django.http import JsonResponse
from ..models import Notice
from rest_framework import permissions
from rest_framework.decorators import api_view
from rest_framework.decorators import permission_classes
from rest_framework.permissions import IsAuthenticated
@api_view(['GET'])
@permission_classes([permissions.IsAuthenticated])
def listAllNotices(request):
output = {}
# No database activity actually occurs until
# we do something to evaluate the queryset.
# list() forces evaluation of a QuerySet
output["list"] = list(Notice.objects.values())
return JsonResponse(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment