|
|
|
@ -1,7 +1,9 @@ |
|
|
|
from rest_framework.generics import ListAPIView, RetrieveAPIView,ListCreateAPIView |
|
|
|
from rest_framework.response import Response |
|
|
|
from django.db.models import Q |
|
|
|
from ..models import BookReference , BookAuthor , BookReferenceImage, BookAttribute |
|
|
|
from ..serializers.reference import BookAuthorSerializer, BookDetailSerializer , BookReferenceSerializer, BookReferenceSyncSerializer, BookAttributeSerializer |
|
|
|
from ..serializers.category import get_localized_text |
|
|
|
from ..docs import book_attributes_create_swagger, book_attributes_list_swagger, book_references_list_swagger, book_authors_list_swagger, book_detail_swagger, reference_sync_swagger |
|
|
|
from utils.pagination import NoPagination |
|
|
|
|
|
|
|
@ -15,6 +17,32 @@ class BookReferencesView(ListAPIView): |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
return super().get(request, *args, **kwargs) |
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
|
queryset = BookReference.objects.all() |
|
|
|
|
|
|
|
# Get search parameter |
|
|
|
search_query = self.request.query_params.get('search', None) |
|
|
|
|
|
|
|
# Apply search filter |
|
|
|
if search_query: |
|
|
|
queryset = self.apply_search_filter(queryset, search_query) |
|
|
|
|
|
|
|
return queryset |
|
|
|
|
|
|
|
def apply_search_filter(self, queryset, search_query): |
|
|
|
""" |
|
|
|
Apply search filter across book titles (JSONField). |
|
|
|
Searches in: title |
|
|
|
""" |
|
|
|
# Search conditions |
|
|
|
search_conditions = Q() |
|
|
|
|
|
|
|
# For JSONFields, search in the JSON string representation |
|
|
|
# This will find matches in the "text" values within the JSON arrays |
|
|
|
search_conditions |= Q(title__icontains=search_query) |
|
|
|
|
|
|
|
return queryset.filter(search_conditions) |
|
|
|
|
|
|
|
|
|
|
|
class BookAuthorView(ListAPIView): |
|
|
|
queryset = BookAuthor.objects.all() |
|
|
|
|