From 3f9d952507474f42b9dee75b99764f6db1f39a6a Mon Sep 17 00:00:00 2001 From: Meefx Date: Tue, 5 Dec 2023 21:30:43 +0700 Subject: [PATCH] add: get rec by id --- rekomendasi/urls.py | 1 + rekomendasi/views.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/rekomendasi/urls.py b/rekomendasi/urls.py index 01b0e2d..3a3f903 100644 --- a/rekomendasi/urls.py +++ b/rekomendasi/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ path('similar-books/', similar_books, name='similar_books'), path('json/', get_recommendations_json, name='get_recommendations_json'), + path('json/', get_recommendations_json_by_id, name='get_recommendations_json_by_id'), path('filter-books-ajax/', filter_books_ajax, name='filter_books_ajax'), path('isbn-search/',isbn_search,name="isbn_search") ] \ No newline at end of file diff --git a/rekomendasi/views.py b/rekomendasi/views.py index 43097b1..a6643c5 100644 --- a/rekomendasi/views.py +++ b/rekomendasi/views.py @@ -69,6 +69,16 @@ def get_recommendations_json(request): data = BookRecommendation.objects.all() return HttpResponse(serializers.serialize("json",data),content_type="application/json") +def get_recommendations_json_by_id(request, id): + book = Book.objects.get(pk = id) + + # Periksa apakah rekomendasi sudah ada + if not has_recommendations(book): + init_recommend_book(book) + + recommendation_books = BookRecommendation.objects.filter(source_book=book) + return HttpResponse(serializers.serialize("json",recommendation_books),content_type="application/json") + @csrf_exempt def filter_books_ajax(request, id): book = Book.objects.get(pk = id)