Browse Source

Ref Crud para Listar GenericRelations

pull/739/head
LeandroRoberto 8 years ago
parent
commit
abfeddb4e9
  1. 2
      sapl/api/urls.py
  2. 14
      sapl/crud/base.py
  3. 5
      sapl/materia/forms.py
  4. 3
      sapl/parlamentares/views.py
  5. 1
      sapl/settings.py

2
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))
]

14
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

5
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)

3
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)

1
sapl/settings.py

@ -75,6 +75,7 @@ INSTALLED_APPS = (
'floppyforms',
'sass_processor',
'rest_framework',
'rest_framework_docs',
) + SAPL_APPS

Loading…
Cancel
Save