Skip to content

Commit

Permalink
likes export
Browse files Browse the repository at this point in the history
  • Loading branch information
Javad-Ak committed Oct 16, 2024
1 parent c8787b0 commit 45949f1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion game/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 45949f1

Please sign in to comment.