You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

10 years ago
  1. from django.contrib import admin
  2. # Register your models here.
  3. from django.contrib.auth.admin import UserAdmin
  4. from django.contrib.auth.models import User
  5. from hc.api.models import Channel, Check
  6. class HcUserAdmin(UserAdmin):
  7. list_display = ('id', 'username', 'email', 'date_joined', 'involvement',
  8. 'is_staff')
  9. ordering = ["-id"]
  10. def involvement(self, user):
  11. result = ""
  12. num_checks = Check.objects.filter(user=user).count()
  13. num_channels = Channel.objects.filter(user=user).count()
  14. if num_checks == 0:
  15. result += "0 checks, "
  16. elif num_checks == 1:
  17. result += "1 check, "
  18. else:
  19. result += "<strong>%d checks</strong>, " % num_checks
  20. if num_channels == 0:
  21. result += "0 channels"
  22. elif num_channels == 1:
  23. result += "1 channel, "
  24. else:
  25. result += "<strong>%d channels</strong>, " % num_channels
  26. return result
  27. involvement.allow_tags = True
  28. admin.site.unregister(User)
  29. admin.site.register(User, HcUserAdmin)