Last active
May 10, 2023 18:14
-
-
Save KC2016/3e3a82079bdaff48591c15696b43a83a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For the implementation, it was used Python decorator in Django REST framework to define a view function that can handle HTTP requests. | |
@api_view(['GET']) | |
def getRakingRecomm(request): | |
category_arg = request.query_params.get('chosen_category') | |
# the ML model returns the id of 3 ranked recommended items based on the category selected on the search bar | |
# recommendation_dir = os.path.join(settings.BASE_DIR, 'm_l', 'recommendation') | |
# sys.path.append(recommendation_dir) | |
# from recommendation_f import create_ranking_df | |
id1, id2, id3 = create_ranking_df(category_arg) | |
obj1 = Item.objects.get(id=id1) | |
obj2 = Item.objects.get(id=id2) | |
obj3 = Item.objects.get(id=id3) | |
ranked_items = [] | |
serialized_obj1 = ItemSerializers(obj1).data | |
ranked_items.append(serialized_obj1) | |
serialized_obj2 = ItemSerializers(obj2).data | |
ranked_items.append(serialized_obj2) | |
serialized_obj3 = ItemSerializers(obj3).data | |
ranked_items.append(serialized_obj3) | |
return Response(ranked_items) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment