Django Cannot resolve keyword 'slug' into field

I want to filter API by building name.

models.py

from django.shortcuts import render
from rest_framework.response import Response
from .models import ReviewData
from .models import BuildingData
from rest_framework.views import APIView
from .serializers import ReviewSerializer
from .serializers import BuildingSerializer
from django.shortcuts import render, get_object_or_404

class BuildingInfoAPI(APIView):
    def get(self, request):
        queryset = BuildingData.objects.all()
        serializer = BuildingSerializer(queryset, many=True)
        return Response(serializer.data)
class ReviewListAPI(APIView):
    def get(self, request, slug):
        queryset = ReviewData.objects.all()
        serializer = ReviewSerializer(queryset, many=True)
        return Response(serializer.data)

views.py

# Create your views here.
from django.shortcuts import render
from rest_framework.response import Response
from .models import ReviewData
from .models import BuildingData
from rest_framework.views import APIView
from .serializers import ReviewSerializer
from .serializers import BuildingSerializer
from django.shortcuts import render, get_object_or_404

class BuildingInfoAPI(APIView):
    def get(self, request):
        queryset = BuildingData.objects.all()
        serializer = BuildingSerializer(queryset, many=True)
        return Response(serializer.data)
class ReviewListAPI(APIView):
    def get(self, request, slug):
        queryset = ReviewData.objects.filter(slug=slug)
        serializer = ReviewSerializer(queryset, many=True)
        return Response(serializer.data)

urls.py

from django.contrib import admin
from django.urls import path
from crawling_data.views import ReviewListAPI
from crawling_data.views import BuildingInfoAPI

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/buildingdata/', BuildingInfoAPI.as_view()),
    path('api/buildingdata/<str:slug>/', ReviewListAPI.as_view())

So my API should look like this

api/buildingdata/A_building

A_Building-review a
A_Building-review b
A_Building-review c

api/buildingdata/B_building

B_Building-review a
B_Building-review b

But this error occurs.

Cannot resolve keyword 'slug' into field. Choices are: building_name, id, review_content, star_num

Where should I fix to filter review by building name?

Back to Top