-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadmin.py
66 lines (56 loc) · 1.69 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import gettext_lazy as _
from core.models import Device
User = get_user_model()
class CustomUserAdmin(UserAdmin):
list_display = [
"username",
"is_active",
"get_full_name",
"email",
"last_login",
"get_devices",
"is_staff",
"is_superuser",
"full_access_to_devices",
]
ordering = ["-is_active", "-last_login"]
fieldsets = (
(None, {"fields": ("username", "password")}),
(
_("Personal info"),
{
"fields": (
"first_name",
"last_name",
"email",
"profile_picture",
"bio",
"contact_url",
)
},
),
(
_("Permissions"),
{
"fields": (
"is_active",
"is_staff",
"is_superuser",
"full_access_to_devices",
"groups",
"user_permissions",
),
},
),
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
)
def get_full_name(self, obj):
return "{} {}".format(obj.first_name, obj.last_name)
get_full_name.short_description = "Full Name"
def get_devices(self, obj):
return [device.codename for device in Device.objects.filter(maintainers=obj)]
get_devices.short_description = "Devices"
admin.site.register(User, CustomUserAdmin)