From 63fc4b9e315ab55bfc8359184af72b7f54c6af42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Thu, 27 May 2021 11:56:08 -0300 Subject: [PATCH] =?UTF-8?q?Adiciona=20lista=20de=20servidores=20na=20edi?= =?UTF-8?q?=C3=A7=C3=A3o=20do=20servi=C3=A7o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/servidores/admin.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/sigi/apps/servidores/admin.py b/sigi/apps/servidores/admin.py index 7e45acf..7d19536 100644 --- a/sigi/apps/servidores/admin.py +++ b/sigi/apps/servidores/admin.py @@ -34,12 +34,41 @@ class ServicoInline(admin.TabularInline): model = Servico fields = ['nome', 'sigla', 'responsavel',] +class ServidorInline(admin.TabularInline): + model = Servidor + fields = ('imagem_foto', 'nome_completo', 'is_active', ) + readonly_fields = ('imagem_foto', 'nome_completo', 'is_active', ) + + def has_add_permission(self, request): + return False + + def has_delete_permission(self, request, obj): + return False + + def imagem_foto(sels, servidor): + if servidor.foto: + return u''.format(url=servidor.foto.url) + else: + return u"" + imagem_foto.short_description = _(u"foto") + imagem_foto.allow_tags = True + + def is_active(self, servidor): + if servidor.user: + return servidor.user.is_active + else: + return False + is_active.admin_order_field = 'user__is_active' + is_active.boolean = True + is_active.short_description = _(u'ativo') + + @admin.register(Servico) class ServicoAdmin(admin.ModelAdmin): list_display = ['sigla', 'nome', 'subordinado', 'responsavel'] list_filter = [ServicoFilter,] search_fields = ['nome', 'sigla',] - inlines = [ServicoInline,] + inlines = [ServicoInline, ServidorInline,] @admin.register(Servidor) class ServidorAdmin(BaseModelAdmin):