Browse Source

Adiciona campo exclude ao crud gerado automaticamente

Fix #224
pull/237/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
b1d9d47a77
  1. 7
      crud.py
  2. 1
      materia/forms.py
  3. 19
      materia/migrations/0019_auto_20160229_1321.py
  4. 22
      materia/migrations/0020_auto_20160229_1324.py
  5. 4
      materia/models.py
  6. 3
      materia/views.py

7
crud.py

@ -62,14 +62,13 @@ def get_field_display(obj, fieldname):
class CrispyLayoutFormMixin(object): class CrispyLayoutFormMixin(object):
def get_form_class(self): def get_form_class(self):
layout = self.layout layout = self.layout
class CrispyForm(forms.ModelForm): class CrispyForm(forms.ModelForm):
class Meta: class Meta:
model = self.model model = self.model
exclude = [] exclude = self.exclude
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(CrispyForm, self).__init__(*args, **kwargs) super(CrispyForm, self).__init__(*args, **kwargs)
@ -254,13 +253,15 @@ class Crud(object):
create_mixin=CrudCreateMixin, create_mixin=CrudCreateMixin,
detail_mixin=CrudDetailMixin, detail_mixin=CrudDetailMixin,
update_mixin=CrudUpdateMixin, update_mixin=CrudUpdateMixin,
delete_mixin=CrudDeleteMixin): delete_mixin=CrudDeleteMixin,
exclude=[]):
class CrudMixin(base_mixin): class CrudMixin(base_mixin):
pass pass
CrudMixin.model = model CrudMixin.model = model
CrudMixin.help_path = help_path CrudMixin.help_path = help_path
CrudMixin.layout = layout CrudMixin.layout = layout
CrudMixin.exclude = exclude
class CrudListView(CrudMixin, list_mixin, ListView): class CrudListView(CrudMixin, list_mixin, ListView):
pass pass

1
materia/forms.py

@ -513,6 +513,7 @@ class FormularioSimplificadoForm(ModelForm):
'em_tramitacao', 'em_tramitacao',
'ementa', 'ementa',
'texto_original'] 'texto_original']
exclude = ['anexadas']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):

19
materia/migrations/0019_auto_20160229_1321.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('materia', '0018_merge'),
]
operations = [
migrations.AlterField(
model_name='materialegislativa',
name='anexadas',
field=models.ManyToManyField(to='materia.MateriaLegislativa', blank=True, related_name='anexo_de', through='materia.Anexada'),
),
]

22
materia/migrations/0020_auto_20160229_1324.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.utils.timezone import utc
import datetime
class Migration(migrations.Migration):
dependencies = [
('materia', '0019_auto_20160229_1321'),
]
operations = [
migrations.AlterField(
model_name='materialegislativa',
name='data_apresentacao',
field=models.DateField(default=datetime.datetime(2016, 2, 29, 16, 24, 24, 963568, tzinfo=utc), verbose_name='Data Apresentação'),
preserve_default=False,
),
]

4
materia/models.py

@ -65,8 +65,7 @@ class MateriaLegislativa(models.Model):
ano = models.PositiveSmallIntegerField(verbose_name=_('Ano')) ano = models.PositiveSmallIntegerField(verbose_name=_('Ano'))
numero_protocolo = models.PositiveIntegerField( numero_protocolo = models.PositiveIntegerField(
blank=True, null=True, verbose_name=_('Núm. Protocolo')) blank=True, null=True, verbose_name=_('Núm. Protocolo'))
data_apresentacao = models.DateField( data_apresentacao = models.DateField(verbose_name=_('Data Apresentação'))
blank=True, null=True, verbose_name=_('Data Apresentação'))
tipo_apresentacao = models.CharField( tipo_apresentacao = models.CharField(
max_length=1, blank=True, max_length=1, blank=True,
verbose_name=_('Tipo de Apresentação'), verbose_name=_('Tipo de Apresentação'),
@ -111,6 +110,7 @@ class MateriaLegislativa(models.Model):
# XXX novo # XXX novo
anexadas = models.ManyToManyField( anexadas = models.ManyToManyField(
'self', 'self',
blank=True,
through='Anexada', through='Anexada',
symmetrical=False, symmetrical=False,
related_name='anexo_de', related_name='anexo_de',

3
materia/views.py

@ -73,6 +73,7 @@ tipo_fim_relatoria_crud = Crud(
]) ])
materia_legislativa_crud = Crud( materia_legislativa_crud = Crud(
MateriaLegislativa, '', [ MateriaLegislativa, '', [
[_('Identificação Básica'), [_('Identificação Básica'),
@ -99,7 +100,7 @@ materia_legislativa_crud = Crud(
[('ementa', 12)], [('ementa', 12)],
[('indexacao', 12)], [('indexacao', 12)],
[('observacao', 12)]], [('observacao', 12)]],
]) ], exclude=['anexadas'])
Anexada_crud = Crud( Anexada_crud = Crud(
Anexada, '', [ Anexada, '', [

Loading…
Cancel
Save