Skip to content

Commit

Permalink
feat: Create custom action to stop games in django admin (#1761)
Browse files Browse the repository at this point in the history
* feat: Create custom action to stop games in django admin

* Update lockfile

* Use constant and try upgrading pip

* Revert to old pipenv version

* Try locking pipfile again

* Update lockfile

* Merge master

* Update lockfile
  • Loading branch information
faucomte97 committed Apr 27, 2023
1 parent 78b8bea commit bce704d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
24 changes: 12 additions & 12 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions aimmo/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ class GameDataAdmin(admin.ModelAdmin):
readonly_fields = ["players", "auth_token"]

def players(self, obj):
players = "\n".join(
[student.new_user.first_name for student in obj.game_class.students.all()]
)
players = players.join(obj.game_class.teacher.new_user.first_name)
teacher_user = obj.game_class.teacher.new_user
players = f"{teacher_user.first_name} {teacher_user.last_name}\n"
players += "\n".join([student.new_user.first_name for student in obj.game_class.students.all()])
return players

def school(self, obj):
Expand All @@ -25,6 +24,15 @@ def school(self, obj):
return None


def stop_game(game_admin, request, queryset):
for game in queryset:
game.status = Game.STOPPED
game.save()


stop_game.short_description = "Stop selected games"


class AvatarDataAdmin(admin.ModelAdmin):
search_fields = ["owner__username", "owner__email"]
list_display = ["id", "owner_name", "game_id"]
Expand All @@ -40,3 +48,5 @@ def game_id(self, obj):

admin.site.register(Game, GameDataAdmin)
admin.site.register(Avatar, AvatarDataAdmin)

GameDataAdmin.actions.append(stop_game)

0 comments on commit bce704d

Please sign in to comment.