diff --git a/sigi/apps/casas/admin.py b/sigi/apps/casas/admin.py index f9571e3..9660d25 100644 --- a/sigi/apps/casas/admin.py +++ b/sigi/apps/casas/admin.py @@ -18,6 +18,7 @@ from sigi.apps.metas.models import PlanoDiretor from sigi.apps.ocorrencias.models import Ocorrencia from sigi.apps.parlamentares.models import Legislatura from sigi.apps.servicos.models import Servico +from sigi.apps.servidores.models import Servidor from sigi.apps.utils import queryset_ascii from sigi.apps.utils.base_admin import BaseModelAdmin @@ -161,6 +162,13 @@ class OcorrenciaInline(admin.TabularInline): can_delete = False +class GerentesContasFilter(admin.filters.RelatedFieldListFilter): + def __init__(self, *args, **kwargs): + super(GerentesContasFilter, self).__init__(*args, **kwargs) + gerentes = Servidor.objects.filter(casas_que_gerencia__isnull=False).order_by('nome_completo').distinct() + self.lookup_choices = [(x.id, x) for x in gerentes] + + class CasaLegislativaAdmin(ImageCroppingMixin, BaseModelAdmin): form = CasaLegislativaForm actions = ['adicionar_casas', ] @@ -168,7 +176,7 @@ class CasaLegislativaAdmin(ImageCroppingMixin, BaseModelAdmin): DiagnosticoInline, BemInline, ServicoInline, PlanoDiretorInline, OcorrenciaInline, ) list_display = ('nome', 'municipio', 'logradouro', 'ult_alt_endereco', 'get_convenios') list_display_links = ('nome',) - list_filter = ('tipo', 'municipio__uf__nome', 'convenio__projeto') + list_filter = ('tipo', ('gerente_contas', GerentesContasFilter), 'municipio__uf__nome', 'convenio__projeto') ordering = ('nome', 'municipio__uf') queyrset = queryset_ascii fieldsets = ( diff --git a/sigi/apps/casas/models.py b/sigi/apps/casas/models.py index 4bbd87d..307245d 100644 --- a/sigi/apps/casas/models.py +++ b/sigi/apps/casas/models.py @@ -49,7 +49,7 @@ class CasaLegislativa(models.Model): codigo_interlegis = models.CharField('Código Interlegis', max_length=3, blank=True) # codigo_interlegis.ts_filter = True - gerente_contas = models.ForeignKey(Servidor, verbose_name="Gerente de contas", null=True, blank=True) + gerente_contas = models.ForeignKey(Servidor, verbose_name="Gerente de contas", null=True, blank=True, related_name='casas_que_gerencia') # Informações de contato logradouro = models.CharField(