Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

likes export #39

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 phone No', '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.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_likes', 'export_games']
export_games.short_description = 'Export Games'
export_likes.short_description = 'Export Likes'
actions_on_top = True

search_fields = ("title", "team")
Expand Down
Loading