diff --git a/sigi/apps/servidores/admin.py b/sigi/apps/servidores/admin.py index e9f912d..5e64ced 100644 --- a/sigi/apps/servidores/admin.py +++ b/sigi/apps/servidores/admin.py @@ -13,11 +13,33 @@ class ServidorFilter(AlphabeticFilter): title = _(u'Nome do Servidor') parameter_name = 'servidor__nome_completo' +class ServicoFilter(admin.SimpleListFilter): + title = _(u"Subordinados à") + parameter_name = 'subordinado__id__exact' + + def lookups(self, request, model_admin): + return ([('None', _(u"Nenhum"))] + + [(s.id, s.nome) for s in Servico.objects.exclude(servico=None)]) + + def queryset(self, request, queryset): + if self.value(): + if self.value() == "None": + queryset = queryset.filter(subordinado=None) + else: + queryset = queryset.filter(subordinado__id=self.value()) + return queryset + + +class ServicoInline(admin.TabularInline): + model = Servico + fields = ['nome', 'sigla', 'responsavel',] + @admin.register(Servico) class ServicoAdmin(admin.ModelAdmin): list_display = ['sigla', 'nome', 'subordinado', 'responsavel'] - list_filter = ['subordinado',] + list_filter = [ServicoFilter,] search_fields = ['nome', 'sigla',] + inlines = [ServicoInline,] @admin.register(Servidor) class ServidorAdmin(BaseModelAdmin): diff --git a/sigi/apps/servidores/migrations/0005_auto_20210423_0904.py b/sigi/apps/servidores/migrations/0005_auto_20210423_0904.py new file mode 100644 index 0000000..5d0fc81 --- /dev/null +++ b/sigi/apps/servidores/migrations/0005_auto_20210423_0904.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('servidores', '0004_auto_20210422_1907'), + ] + + operations = [ + migrations.AlterModelOptions( + name='servico', + options={'ordering': ('-subordinado__sigla', 'nome'), 'verbose_name': 'servi\xe7o', 'verbose_name_plural': 'servi\xe7os'}, + ), + ] diff --git a/sigi/apps/servidores/models.py b/sigi/apps/servidores/models.py index 7aff853..48c7128 100644 --- a/sigi/apps/servidores/models.py +++ b/sigi/apps/servidores/models.py @@ -24,7 +24,7 @@ class Servico(models.Model): ) class Meta: - ordering = ('nome',) + ordering = ('-subordinado__sigla', 'nome',) verbose_name = _(u'serviço') verbose_name_plural = _(u'serviços')