Browse Source

Nicer Django admin

pull/7/head
Pēteris Caune 9 years ago
parent
commit
749114d856
2 changed files with 43 additions and 1 deletions
  1. +17
    -0
      hc/accounts/admin.py
  2. +26
    -1
      hc/api/admin.py

+ 17
- 0
hc/accounts/admin.py View File

@ -1,3 +1,20 @@
from django.contrib import admin
# Register your models here.
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from hc.api.models import Check
class HcUserAdmin(UserAdmin):
list_display = ('id', 'username', 'email', 'date_joined', 'num_checks',
'is_staff')
ordering = ["-id"]
def num_checks(self, user):
return Check.objects.filter(user=user).count()
admin.site.unregister(User)
admin.site.register(User, HcUserAdmin)

+ 26
- 1
hc/api/admin.py View File

@ -3,6 +3,21 @@ from django.contrib import admin
from hc.api.models import Check, Ping
class OwnershipListFilter(admin.SimpleListFilter):
title = "Ownership"
parameter_name = 'ownership'
def lookups(self, request, model_admin):
return (
('assigned', "Assigned"),
)
def queryset(self, request, queryset):
if self.value() == 'assigned':
return queryset.filter(user__isnull=False)
return queryset
@admin.register(Check)
class ChecksAdmin(admin.ModelAdmin):
@ -16,6 +31,8 @@ class ChecksAdmin(admin.ModelAdmin):
list_select_related = ("user", )
actions = ["send_alert"]
list_filter = ("status", OwnershipListFilter)
def email(self, obj):
return obj.user.email if obj.user else None
@ -30,4 +47,12 @@ class ChecksAdmin(admin.ModelAdmin):
@admin.register(Ping)
class PingsAdmin(admin.ModelAdmin):
list_display = ("id", "created", "owner", "method", "ua")
list_select_related = ("owner", )
list_display = ("id", "created", "check_name", "email", "scheme", "method",
"ua")
def check_name(self, obj):
return obj.owner.name if obj.owner.name else obj.owner.code
def email(self, obj):
return obj.owner.user.email if obj.owner.user else None

Loading…
Cancel
Save