med/sporz/admin.py

38 lines
1.0 KiB
Python

# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib import admin
from med.admin import admin_site
from .models import GameSave, Player
class PlayerInline(admin.TabularInline):
model = Player
class GameSaveAdmin(admin.ModelAdmin):
inlines = [PlayerInline, ]
list_display = ('__str__', 'game_master', 'game_has_ended')
date_hierarchy = 'created_at'
def has_change_permission(self, request, obj=None):
"""
If user is game master then authorize edit
"""
if obj and obj.game_master == request.user:
return True
return super().has_change_permission(request, obj)
def has_delete_permission(self, request, obj=None):
"""
If user is game master then authorize deletion
"""
if obj and obj.game_master == request.user:
return True
return super().has_delete_permission(request, obj)
admin_site.register(GameSave, GameSaveAdmin)