Source code for coalition.stakeholders.admin

from django.contrib import admin

from .models import Stakeholder


@admin.register(Stakeholder)
[docs] class StakeholderAdmin(admin.ModelAdmin):
[docs] list_display = ( "get_full_name", "organization", "type", "city", "state", "county", "email_updates", "endorsement_count", "created_at", )
[docs] list_filter = ("type", "state", "email_updates", "created_at")
[docs] search_fields = ( "first_name", "last_name", "organization", "email", "city", "county", "zip_code", )
[docs] ordering = ("-created_at",)
[docs] readonly_fields = ( "location", "congressional_district", "state_senate_district", "state_house_district", "created_at", "updated_at", )
[docs] fieldsets = ( ( "Contact Information", { "fields": ( "first_name", "last_name", "organization", "role", "email", "type", "email_updates", ), }, ), ( "Address", { "fields": ( "street_address", "city", "state", "zip_code", "county", ), }, ), ( "Geographic Information", { "fields": ( "location", "congressional_district", "state_senate_district", "state_house_district", ), "description": ( "These fields are automatically populated based on the address" ), }, ), ( "System Fields", {"fields": ("created_at", "updated_at"), "classes": ("collapse",)}, ), )
[docs] def get_full_name(self, obj: Stakeholder) -> str: """Display full name from first and last name""" return obj.name
get_full_name.short_description = "Name" get_full_name.admin_order_field = "first_name" # Allow sorting
[docs] def endorsement_count(self, obj: Stakeholder) -> int: """Display count of endorsements""" return obj.endorsements.count()
endorsement_count.short_description = "Endorsements"