diff --git a/sapl/norma/models.py b/sapl/norma/models.py index a36368e8b..8d5dbce82 100644 --- a/sapl/norma/models.py +++ b/sapl/norma/models.py @@ -114,6 +114,13 @@ class NormaJuridica(models.Model): verbose_name_plural = _('Normas Jurídicas') ordering = ['-data', '-numero'] + def get_normas_relacionadas(self): + principais = NormaRelacionada.objects.filter( + norma_principal=self.id) + relacionadas = NormaRelacionada.objects.filter( + norma_relacionada=self.id) + return (principais, relacionadas) + def __str__(self): return _('%(tipo)s nº %(numero)s de %(data)s') % { 'tipo': self.tipo, diff --git a/sapl/norma/views.py b/sapl/norma/views.py index bdb74c5e0..10dbf4ad2 100644 --- a/sapl/norma/views.py +++ b/sapl/norma/views.py @@ -130,16 +130,7 @@ class NormaCrud(Crud): return reverse('%s:%s' % (namespace, 'norma_pesquisa')) class DetailView(Crud.DetailView): - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - principais = NormaRelacionada.objects.filter( - norma_principal=self.object.pk) - relacionadas = NormaRelacionada.objects.filter( - norma_relacionada=self.object.pk) - context['principais'] = principais - context['relacionadas'] = relacionadas - return context + pass class DeleteView(Crud.DeleteView): diff --git a/sapl/templates/norma/normajuridica_detail.html b/sapl/templates/norma/normajuridica_detail.html index 4e2585988..ab1df921e 100644 --- a/sapl/templates/norma/normajuridica_detail.html +++ b/sapl/templates/norma/normajuridica_detail.html @@ -36,8 +36,9 @@

Relacionamentos

- {% if principais|length > 0 %} - {% for p in principais %} + + {% if object.get_normas_relacionadas.0|length > 0 %} + {% for p in object.get_normas_relacionadas.0 %}