Browse Source

references serach added.

master
Mohsen Taba 5 months ago
parent
commit
5a97a214a1
  1. 15
      apps/hadis/docs.py
  2. 28
      apps/hadis/views/reference.py

15
apps/hadis/docs.py

@ -1322,8 +1322,13 @@ book_references_list_swagger = swagger_auto_schema(
**Key Features:**
- Returns a paginated list of book references
- Supports search functionality for book titles
- Includes metadata such as title, description, rating, and volume info
**Search Functionality:**
- Search parameter performs case-insensitive search across book titles
- Supports partial matching for easy discovery
**Response Structure:**
- `count`: Total number of books
- `results`: Array of book objects
@ -1334,6 +1339,16 @@ book_references_list_swagger = swagger_auto_schema(
operation_summary="List Book References",
operation_id="listBookReferences",
tags=['Hadis'],
manual_parameters=[
openapi.Parameter(
'search',
openapi.IN_QUERY,
description="Search term to filter book references by title. Case-insensitive partial matching.",
type=openapi.TYPE_STRING,
required=False,
example="sahih"
)
],
responses={
status.HTTP_200_OK: openapi.Response(
description="Paginated list of book references",

28
apps/hadis/views/reference.py

@ -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()

Loading…
Cancel
Save