admin.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from django.conf import settings
  2. from django.contrib import admin
  3. from django.core.urlresolvers import reverse
  4. from django.utils.translation import ugettext_lazy as _
  5. import models
  6. class StateAdmin(admin.ModelAdmin):
  7. list_display = ['name']
  8. class PartyAdmin(admin.ModelAdmin):
  9. list_display = ['name', 'shortname']
  10. class PoliticianAdmin(admin.ModelAdmin):
  11. def unique_url(self, obj):
  12. return '%s%s' % (
  13. settings.BASE_URL,
  14. reverse('politician_edit_profile', args=(obj.unique_key,))
  15. )
  16. unique_url.short_description = _('unique_url')
  17. def get_readonly_fields(self, request, obj=None):
  18. if obj:
  19. return self.readonly_fields
  20. return ()
  21. list_display = ['first_name', 'last_name', 'email', 'unique_url']
  22. readonly_fields = ('unique_url',)
  23. exclude = ('unique_key',)
  24. class CategoryAdmin(admin.ModelAdmin):
  25. list_display = ['name']
  26. class LinkTypeAdmin(admin.ModelAdmin):
  27. list_display = ['name']
  28. class QuestionAdmin(admin.ModelAdmin):
  29. def get_category(self, obj):
  30. return obj.category.__unicode__()
  31. get_category.short_description = _('category')
  32. list_display = ['question_number', 'get_category', 'text']
  33. admin.site.register(models.State, StateAdmin)
  34. admin.site.register(models.Party, PartyAdmin)
  35. admin.site.register(models.Politician, PoliticianAdmin)
  36. admin.site.register(models.Category, CategoryAdmin)
  37. admin.site.register(models.Question, QuestionAdmin)
  38. admin.site.register(models.LinkType, LinkTypeAdmin)