From 45949f1e8f485e207dc20fc5d00732a8ac592ced Mon Sep 17 00:00:00 2001 From: MJ Akbari Date: Wed, 16 Oct 2024 22:00:52 +0330 Subject: [PATCH 1/3] likes export --- game/admin.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/game/admin.py b/game/admin.py index dbace87..6ba5f67 100644 --- a/game/admin.py +++ b/game/admin.py @@ -27,8 +27,23 @@ def export_games(self, request, queryset): else: return ExcelResponse(data=data, worksheet_name="games", output_filename="games") - actions = ['export_games'] + def export_likes(self, request, queryset): + data = [] + headers = ['game', 'liker_name', 'liker_email', 'timestamp'] + data.append(headers) + + for game in queryset.all(): + for like in game.likes.all(): + data.append([game.title, like.user.first_name, like.user.email, like.timestamp]) + + if not data: + return JsonResponse({"message": "Nothing Found"}) + else: + return ExcelResponse(data=data, worksheet_name="likes", output_filename="games") + + actions = ['export_games', 'export_likes'] export_games.short_description = 'Export Games' + export_likes.short_description = 'Export Likes' actions_on_top = True search_fields = ("title", "team") From 93e39911cf5ce84e67a2b9111ecaf945a5d9c68c Mon Sep 17 00:00:00 2001 From: MJ Akbari Date: Wed, 16 Oct 2024 22:07:10 +0330 Subject: [PATCH 2/3] likes export 2 --- game/admin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/game/admin.py b/game/admin.py index 6ba5f67..770b9e5 100644 --- a/game/admin.py +++ b/game/admin.py @@ -29,19 +29,19 @@ def export_games(self, request, queryset): def export_likes(self, request, queryset): data = [] - headers = ['game', 'liker_name', 'liker_email', 'timestamp'] + headers = ['game', 'liker name', 'liker email', 'liker phone No', 'timestamp'] data.append(headers) for game in queryset.all(): for like in game.likes.all(): - data.append([game.title, like.user.first_name, like.user.email, like.timestamp]) + data.append([game.title, like.user.first_name, like.user.phone_number, like.user.email, like.timestamp]) if not data: return JsonResponse({"message": "Nothing Found"}) else: return ExcelResponse(data=data, worksheet_name="likes", output_filename="games") - actions = ['export_games', 'export_likes'] + actions = ['export_likes', 'export_games'] export_games.short_description = 'Export Games' export_likes.short_description = 'Export Likes' actions_on_top = True From b75396fa932b354c772beac387024c938fb3b100 Mon Sep 17 00:00:00 2001 From: MJ Akbari Date: Wed, 16 Oct 2024 22:08:03 +0330 Subject: [PATCH 3/3] likes export 3 --- game/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/admin.py b/game/admin.py index 770b9e5..0fe4fff 100644 --- a/game/admin.py +++ b/game/admin.py @@ -29,7 +29,7 @@ def export_games(self, request, queryset): def export_likes(self, request, queryset): data = [] - headers = ['game', 'liker name', 'liker email', 'liker phone No', 'timestamp'] + headers = ['game', 'liker name', 'liker phone No', 'liker email', 'timestamp'] data.append(headers) for game in queryset.all():