8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-24 20:33:11 +00:00

Create custom ModelAdmin class

This commit is contained in:
Alexandre Iooss 2019-03-01 10:18:42 +01:00
parent 3a28e4aebc
commit 040b15dcd1
2 changed files with 11 additions and 8 deletions

View file

@ -1,10 +1,16 @@
from django.contrib.admin.sites import AdminSite from django.contrib import admin
class UserAdmin(AdminSite): class UserAdmin(admin.sites.AdminSite):
def has_permission(self, request): def has_permission(self, request):
"""This admin site doesn't require being staff""" """This admin site doesn't require being staff"""
return request.user.is_active return request.user.is_active
class ModelUserAdmin(admin.ModelAdmin):
# Display actions on changelist bottom bu default
actions_on_bottom = True
# Defines new management site
user_admin_site = UserAdmin(name='user_admin') user_admin_site = UserAdmin(name='user_admin')

View file

@ -32,8 +32,7 @@ from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from reversion.admin import VersionAdmin from reversion.admin import VersionAdmin
from useradmin.admin import user_admin_site from useradmin.admin import ModelUserAdmin, user_admin_site
from .models import ( from .models import (
User, User,
EMailAddress, EMailAddress,
@ -85,10 +84,9 @@ class LdapServiceUserGroupAdmin(admin.ModelAdmin):
search_fields = ('name',) search_fields = ('name',)
class SchoolAdmin(VersionAdmin): class SchoolAdmin(VersionAdmin, ModelUserAdmin):
"""Administration, gestion des écoles""" """Administration, gestion des écoles"""
list_display = ('name',) list_display = ('name',)
actions_on_bottom = True
class ListRightAdmin(VersionAdmin): class ListRightAdmin(VersionAdmin):
@ -97,10 +95,9 @@ class ListRightAdmin(VersionAdmin):
list_display = ('unix_name',) list_display = ('unix_name',)
class ListShellAdmin(VersionAdmin): class ListShellAdmin(VersionAdmin, ModelUserAdmin):
"""Gestion de la liste des shells coté admin""" """Gestion de la liste des shells coté admin"""
list_display = ('shell',) list_display = ('shell',)
actions_on_bottom = True
class RequestAdmin(admin.ModelAdmin): class RequestAdmin(admin.ModelAdmin):