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.

38 lines
1.0 KiB

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