Reputation: 531
I was using function based api like
{host}:{port}/api/food/<year>/<month>/<day>/
Now, I have new viewset for model Food.
{host}:{port}/food/
I hope to integrate this apis to one ModelViewSet so i did like below.
{host}:{port}/food/files/<year>/<month>/<day>/
{host}:{port}/food/
class FoodViewSet(viewsets.ModelViewSet):
queryset = Food.objects.all()
permission_classes = [blahblah]
authentication_classes = [blahblah]
def list(self, request, *args, **kwargs):
...
return Response(blahblah)
def create(self, request, *args, **kwargs):
...
return Response(blahblah)
@action(['GET'], detail=True)
def files(self, request, year, month, day):
...
return Response(blahblah)
Upvotes: 1
Views: 1147
Reputation: 531
Sorry, I clear this problem with query url like below.
{host}:{port}/food/files/?year=2019&month=02&day=27
@action(['GET'], detail=False)
def files(self, request):
year = request.query_params.get('year')
month = request.query_params.get('month')
day = request.query_params.get('day')
Upvotes: 1