Skip to content

Commit

Permalink
Merge pull request #37 from AUTGamecraft/refurbish
Browse files Browse the repository at this point in the history
admin for games
  • Loading branch information
Javad-Ak authored Oct 13, 2024
2 parents 4dfbe1f + 41620fe commit b85bf8d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
29 changes: 28 additions & 1 deletion game/admin.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
from django.contrib import admin
from django.http import JsonResponse
from excel_response import ExcelResponse

from game.models import Game, Comment, Like


# Register your models here.


@admin.register(Game)
class GameAdmin(admin.ModelAdmin):
list_display = ("id", "title", "timestamp", "is_verified")
def export_games(self, request, queryset):
data = []
headers = ['title', 'team', 'game_link', 'timestamp', 'is_verified', 'members']
data.append(headers)

for game in queryset.all():
members = ""
for member in game.team.members.all():
members += member.first_name + ", "

data.append([game.title, game.team.name, game.game_link, game.timestamp, game.is_verified, members])

if not data:
return JsonResponse({"message": "Nothing Found"})
else:
return ExcelResponse(data=data, worksheet_name="games", output_filename="games")

actions = ['export_games']
export_games.short_description = 'Export Games'
actions_on_top = True

search_fields = ("title", "team")
list_display = ("id", "title", "team", "timestamp", "is_verified")


@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
list_display = ("id", "user", "timestamp", "text")


@admin.register(Like)
class LikeAdmin(admin.ModelAdmin):
list_display = ("id", "user", "timestamp", "game")
3 changes: 3 additions & 0 deletions user/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def payment_state(self, obj):
export_enrolled_teams.short_description = 'Export enrolled teams'
actions_on_top = True

# search by fields
search_fields = ("name",)

readonly_fields = ['payment_state', ]
list_display = ['id', 'name', 'state', 'member_count']
list_filter = ['state']
Expand Down

0 comments on commit b85bf8d

Please sign in to comment.