Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
837 B
5
Indexable
Never
from django.shortcuts import render
from rest_framework.decorators import api_view
from rest_framework.response import Response
from .serializer import CalendarSerializer
from .models import Calendar
from rest_framework import status
from user_service.models import Part

# Create your views here.
@api_view(['GET'])
def list_calender_by_part(request,id_part):
    part=Part.objects.get(id_part=id_part)
    data=request.GET
    if part:
        day=data.get("day_calendar")
        list_calendar=Calendar.objects.filter(part=part,day_calendar=day)
        serializer = CalendarSerializer(list_calendar,many=True)
        return Response({"data":serializer.data,"message":"Success","code":200},status=status.HTTP_200_OK)
    return Response({"data":"","message":"Failded","code":400},status=status.HTTP_400_BAD_REQUEST)