1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-11-27 00:47:10 +00:00

Autoselect user in admin

This commit is contained in:
Alexandre Iooss 2019-08-16 14:34:16 +02:00
parent 21c1dd067a
commit b41fe3525b
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
2 changed files with 20 additions and 0 deletions

View File

@ -85,6 +85,16 @@ class EmpruntAdmin(VersionAdmin):
permanencier_rendu_custom.short_description = _('given back to') permanencier_rendu_custom.short_description = _('given back to')
permanencier_rendu_custom.allow_tags = True permanencier_rendu_custom.allow_tags = True
def add_view(self, request, form_url='', extra_context=None):
"""
Autoselect keyholder registering a new borrowed item
"""
# Make GET data mutable
data = request.GET.copy()
data['permanencier_emprunt'] = request.user
request.GET = data
return super().add_view(request, form_url, extra_context)
class JeuAdmin(VersionAdmin): class JeuAdmin(VersionAdmin):
list_display = ('name', 'proprietaire', 'duree', 'nombre_joueurs_min', list_display = ('name', 'proprietaire', 'duree', 'nombre_joueurs_min',

View File

@ -33,5 +33,15 @@ class GameSaveAdmin(admin.ModelAdmin):
return True return True
return super().has_delete_permission(request, obj) return super().has_delete_permission(request, obj)
def add_view(self, request, form_url='', extra_context=None):
"""
Autoselect game master when creating a new game
"""
# Make GET data mutable
data = request.GET.copy()
data['game_master'] = request.user
request.GET = data
return super().add_view(request, form_url, extra_context)
admin_site.register(GameSave, GameSaveAdmin) admin_site.register(GameSave, GameSaveAdmin)