diff --git a/sapl/api/urls.py b/sapl/api/urls.py index 324a51b66..32c9226e2 100644 --- a/sapl/api/urls.py +++ b/sapl/api/urls.py @@ -17,8 +17,8 @@ urlpatterns_api = [ url(r'^autor', AutorListView.as_view(), name='autor_list'), + url(r'^docs', include('rest_framework_docs.urls')), ] - urlpatterns = [ url(r'^api/', include(urlpatterns_api)) ] diff --git a/sapl/crud/base.py b/sapl/crud/base.py index dcbb74820..694898115 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -10,6 +10,7 @@ from django.conf.urls import url from django.contrib.auth.mixins import PermissionRequiredMixin from django.core.urlresolvers import reverse from django.db import models +from django.db.models.fields.related import ForeignKey from django.http.response import Http404 from django.utils.decorators import classonlymethod from django.utils.encoding import force_text @@ -1028,10 +1029,17 @@ class MasterDetailCrud(Crud): parent_model = None if '__' in obj.parent_field: fields = obj.parent_field.split('__') - parent_model = self.model + parent_model = pm = self.model for field in fields: - parent_model = getattr( - parent_model, field).field.related_model + pm = getattr(pm, field) + if isinstance(pm.field, ForeignKey): + parent_model = getattr( + parent_model, field).field.related_model + else: + parent_model = getattr( + parent_model, field).rel.related_model + pm = parent_model + else: parent_model = getattr( self.model, obj.parent_field).field.related_model diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 30663200e..b41549018 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -1,6 +1,5 @@ from datetime import datetime -import django_filters from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout from django import forms @@ -9,7 +8,9 @@ from django.db import models from django.db.models import Max from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ +import django_filters +from sapl.base.models import Autor from sapl.comissoes.models import Comissao from sapl.crispy_layout_mixin import form_actions, to_row from sapl.norma.models import (LegislacaoCitada, NormaJuridica, @@ -19,7 +20,7 @@ from sapl.settings import MAX_DOC_UPLOAD_SIZE from sapl.utils import (RANGE_ANOS, RangeWidgetOverride, autor_label, autor_modal) -from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria, +from .models import (AcompanhamentoMateria, Anexada, Autoria, DespachoInicial, DocumentoAcessorio, MateriaLegislativa, Numeracao, Proposicao, Relatoria, TipoMateriaLegislativa, Tramitacao, UnidadeTramitacao) diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index cf64d0bde..d31e4557d 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -59,14 +59,13 @@ class RelatoriaParlamentarCrud(CrudBaseForListAndDetailExternalAppView): class ProposicaoParlamentarCrud(CrudBaseForListAndDetailExternalAppView): model = Proposicao list_field_names = ['tipo', 'descricao'] - parent_field = 'autor__parlamentar' + parent_field = 'autor__parlamentar_set' namespace = AppConfig.name class ListView(CrudBaseForListAndDetailExternalAppView.ListView): def get_queryset(self): return super().get_queryset().filter( - autor__parlamentar_id=self.kwargs['pk'], data_envio__isnull=False) diff --git a/sapl/settings.py b/sapl/settings.py index 2c60ef15d..b0021b113 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -75,6 +75,7 @@ INSTALLED_APPS = ( 'floppyforms', 'sass_processor', 'rest_framework', + 'rest_framework_docs', ) + SAPL_APPS