반응형
❤️🔥TIL : Today I Learned❤️🔥
그날그날 내가 공부한 것을 정리하는 것
내일배움캠프 AI트랙 79day
https://www.django-rest-framework.org/api-guide/filtering/
DjangoFilterBackend
pip install django-filter
INSTALLED_APPS = [
...
'django_filters',
...
]
REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
}
from django_filters.rest_framework import DjangoFilterBackend
class UserListView(generics.ListAPIView):
...
filter_backends = [DjangoFilterBackend]
class ProductList(generics.ListAPIView):
queryset = Product.objects.all()
serializer_class = ProductSerializer
filter_backends = [DjangoFilterBackend]
filterset_fields = ['category', 'in_stock']
http://example.com/api/products?category=clothing&in_stock=True
반응형