Django Не удается преобразовать ключевое слово 'slug' в поле
Я хочу фильтровать API по названию здания.
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())
Итак, мой API должен выглядеть следующим образом
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
Но возникает эта ошибка.
Cannot resolve keyword 'slug' into field. Choices are: building_name, id, review_content, star_num
Где я должен исправить, чтобы фильтровать обзоры по названию здания?