From ab189888952e00333e75504cf1d5c9371dc1d408 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Mon, 8 Jun 2015 20:19:10 -0300 Subject: [PATCH] Remove cod_ pks and change refs to FKs --- comissoes/models.py | 5 ----- lexml/models.py | 2 -- materia/models.py | 23 +++-------------------- norma/models.py | 8 ++------ parlamentares/models.py | 14 +++----------- protocoloadm/models.py | 29 ++++++++++++++--------------- sessao/models.py | 2 +- 7 files changed, 23 insertions(+), 60 deletions(-) diff --git a/comissoes/models.py b/comissoes/models.py index 41b886407..0be2ddb95 100644 --- a/comissoes/models.py +++ b/comissoes/models.py @@ -4,7 +4,6 @@ from parlamentares.models import Parlamentar class TipoComissao(models.Model): - tip_comissao = models.AutoField(primary_key=True) nom_tipo_comissao = models.CharField(max_length=50) sgl_natureza_comissao = models.CharField(max_length=1) sgl_tipo_comissao = models.CharField(max_length=10) @@ -12,7 +11,6 @@ class TipoComissao(models.Model): class Comissao(models.Model): - cod_comissao = models.AutoField(primary_key=True) tip_comissao = models.ForeignKey(TipoComissao) nom_comissao = models.CharField(max_length=60) sgl_comissao = models.CharField(max_length=10) @@ -36,19 +34,16 @@ class Comissao(models.Model): class PeriodoCompComissao(models.Model): - cod_periodo_comp = models.AutoField(primary_key=True) dat_inicio_periodo = models.DateField() dat_fim_periodo = models.DateField(blank=True, null=True) class CargoComissao(models.Model): - ### nome = models.CharField(max_length=50) ind_unico = models.IntegerField() class ComposicaoComissao(models.Model): - cod_comp_comissao = models.AutoField(primary_key=True) parlamentar = models.ForeignKey(Parlamentar) comissao = models.ForeignKey(Comissao) periodo_comp = models.ForeignKey(PeriodoCompComissao) diff --git a/lexml/models.py b/lexml/models.py index e0b6231ff..b0fb641b4 100644 --- a/lexml/models.py +++ b/lexml/models.py @@ -2,7 +2,6 @@ from django.db import models class LexmlRegistroProvedor(models.Model): - cod_provedor = models.AutoField(primary_key=True) id_provedor = models.IntegerField() nom_provedor = models.CharField(max_length=255) sgl_provedor = models.CharField(max_length=15) @@ -14,7 +13,6 @@ class LexmlRegistroProvedor(models.Model): class LexmlRegistroPublicador(models.Model): - cod_publicador = models.AutoField(primary_key=True) id_publicador = models.IntegerField() nom_publicador = models.CharField(max_length=255) adm_email = models.CharField(max_length=50, blank=True, null=True) diff --git a/materia/models.py b/materia/models.py index ef9c578d2..b0ea65091 100644 --- a/materia/models.py +++ b/materia/models.py @@ -5,7 +5,6 @@ from parlamentares.models import Parlamentar, Partido class TipoMateriaLegislativa(models.Model): - tip_materia = models.AutoField(primary_key=True) sgl_tipo_materia = models.CharField(max_length=5) des_tipo_materia = models.CharField(max_length=50) ind_num_automatica = models.IntegerField() @@ -13,18 +12,15 @@ class TipoMateriaLegislativa(models.Model): class RegimeTramitacao(models.Model): - cod_regime_tramitacao = models.AutoField(primary_key=True) des_regime_tramitacao = models.CharField(max_length=50) class Origem(models.Model): - cod_origem = models.AutoField(primary_key=True) sgl_origem = models.CharField(max_length=10) nom_origem = models.CharField(max_length=50) class MateriaLegislativa(models.Model): - cod_materia = models.AutoField(primary_key=True) tip_id_basica = models.ForeignKey(TipoMateriaLegislativa) num_protocolo = models.IntegerField(blank=True, null=True) num_ident_basica = models.IntegerField() @@ -56,7 +52,6 @@ class MateriaLegislativa(models.Model): class AcompMateria(models.Model): - cod_cadastro = models.AutoField(primary_key=True) materia = models.ForeignKey(MateriaLegislativa) end_email = models.CharField(max_length=100) txt_hash = models.CharField(max_length=8) @@ -70,22 +65,19 @@ class Anexada(models.Model): class AssuntoMateria(models.Model): - cod_assunto = models.IntegerField(primary_key=True) des_assunto = models.CharField(max_length=200) des_dispositivo = models.CharField(max_length=50) class TipoAutor(models.Model): - tip_autor = models.IntegerField(primary_key=True) des_tipo_autor = models.CharField(max_length=50) class Autor(models.Model): - cod_autor = models.AutoField(primary_key=True) partido = models.ForeignKey(Partido, blank=True, null=True) comissao = models.ForeignKey(Comissao, blank=True, null=True) parlamentar = models.ForeignKey(Parlamentar, blank=True, null=True) - tip_autor = models.ForeignKey(TipoAutor) + tipo = models.ForeignKey(TipoAutor) nom_autor = models.CharField(max_length=50, blank=True, null=True) des_cargo = models.CharField(max_length=50, blank=True, null=True) col_username = models.CharField(max_length=50, blank=True, null=True) @@ -104,14 +96,13 @@ class DespachoInicial(models.Model): class TipoDocumento(models.Model): - tip_documento = models.AutoField(primary_key=True) des_tipo_documento = models.CharField(max_length=50) class DocumentoAcessorio(models.Model): cod_documento = models.AutoField(primary_key=True) materia = models.ForeignKey(MateriaLegislativa) - tip_documento = models.ForeignKey(TipoDocumento) + tipo = models.ForeignKey(TipoDocumento) nom_documento = models.CharField(max_length=30) dat_documento = models.DateField(blank=True, null=True) nom_autor_documento = models.CharField(max_length=50, blank=True, null=True) @@ -134,7 +125,6 @@ class Numeracao(models.Model): class Orgao(models.Model): - cod_orgao = models.AutoField(primary_key=True) nom_orgao = models.CharField(max_length=60) sgl_orgao = models.CharField(max_length=10) ind_unid_deliberativa = models.IntegerField() @@ -143,12 +133,10 @@ class Orgao(models.Model): class TipoFimRelatoria(models.Model): - tip_fim_relatoria = models.AutoField(primary_key=True) des_fim_relatoria = models.CharField(max_length=50) class Relatoria(models.Model): - cod_relatoria = models.AutoField(primary_key=True) materia = models.ForeignKey(MateriaLegislativa) parlamentar = models.ForeignKey(Parlamentar) tip_fim_relatoria = models.ForeignKey(TipoFimRelatoria, blank=True, null=True) @@ -166,7 +154,6 @@ class Parecer(models.Model): class TipoProposicao(models.Model): - tip_proposicao = models.AutoField(primary_key=True) des_tipo_proposicao = models.CharField(max_length=50) ind_mat_ou_doc = models.CharField(max_length=1) tip_mat_ou_doc = models.IntegerField() @@ -174,10 +161,9 @@ class TipoProposicao(models.Model): class Proposicao(models.Model): - cod_proposicao = models.AutoField(primary_key=True) materia = models.ForeignKey(MateriaLegislativa, blank=True, null=True) autor = models.ForeignKey(Autor) - tip_proposicao = models.ForeignKey(TipoProposicao) + tipo = models.ForeignKey(TipoProposicao) dat_envio = models.DateTimeField() dat_recebimento = models.DateTimeField(blank=True, null=True) txt_descricao = models.CharField(max_length=100) @@ -188,7 +174,6 @@ class Proposicao(models.Model): class StatusTramitacao(models.Model): - cod_status = models.AutoField(primary_key=True) sgl_status = models.CharField(max_length=10) des_status = models.CharField(max_length=60) ind_fim_tramitacao = models.IntegerField() @@ -196,14 +181,12 @@ class StatusTramitacao(models.Model): class UnidadeTramitacao(models.Model): - cod_unid_tramitacao = models.AutoField(primary_key=True) comissao = models.ForeignKey(Comissao, blank=True, null=True) orgao = models.ForeignKey(Orgao, blank=True, null=True) parlamentar = models.ForeignKey(Parlamentar, blank=True, null=True) class Tramitacao(models.Model): - cod_tramitacao = models.AutoField(primary_key=True) status = models.ForeignKey(StatusTramitacao, blank=True, null=True) materia = models.ForeignKey(MateriaLegislativa) dat_tramitacao = models.DateField(blank=True, null=True) diff --git a/norma/models.py b/norma/models.py index 7783bd6da..29fdb4aa4 100644 --- a/norma/models.py +++ b/norma/models.py @@ -4,21 +4,18 @@ from materia.models import MateriaLegislativa class AssuntoNorma(models.Model): - cod_assunto = models.AutoField(primary_key=True) des_assunto = models.CharField(max_length=50) des_estendida = models.CharField(max_length=250, blank=True, null=True) class TipoNormaJuridica(models.Model): - tip_norma = models.AutoField(primary_key=True) voc_lexml = models.CharField(max_length=50, blank=True, null=True) sgl_tipo_norma = models.CharField(max_length=3) des_tipo_norma = models.CharField(max_length=50) class NormaJuridica(models.Model): - cod_norma = models.AutoField(primary_key=True) - tip_norma = models.ForeignKey(TipoNormaJuridica) + tipo = models.ForeignKey(TipoNormaJuridica) materia = models.ForeignKey(MateriaLegislativa, blank=True, null=True) num_norma = models.IntegerField() ano_norma = models.SmallIntegerField() @@ -32,7 +29,7 @@ class NormaJuridica(models.Model): txt_indexacao = models.TextField(blank=True, null=True) txt_observacao = models.TextField(blank=True, null=True) ind_complemento = models.IntegerField(blank=True, null=True) - cod_assunto = models.CharField(max_length=16) + assunto = models.ForeignKey(AssuntoNorma) # XXX was a CharField (attention on migrate) dat_vigencia = models.DateField(blank=True, null=True) timestamp = models.DateTimeField() @@ -56,7 +53,6 @@ class LegislacaoCitada(models.Model): class VinculoNormaJuridica(models.Model): - cod_vinculo = models.AutoField(primary_key=True) norma_referente = models.ForeignKey(NormaJuridica, related_name='+') norma_referida = models.ForeignKey(NormaJuridica, related_name='+') tip_vinculo = models.CharField(max_length=1, blank=True, null=True) diff --git a/parlamentares/models.py b/parlamentares/models.py index 3da9889d0..ae57dea63 100644 --- a/parlamentares/models.py +++ b/parlamentares/models.py @@ -18,14 +18,12 @@ class SessaoLegislativa(models.Model): class Coligacao(models.Model): - cod_coligacao = models.AutoField(primary_key=True) legislatura = models.ForeignKey(Legislatura) nom_coligacao = models.CharField(max_length=50) num_votos_coligacao = models.IntegerField(blank=True, null=True) class Partido(models.Model): - cod_partido = models.AutoField(primary_key=True) sgl_partido = models.CharField(max_length=9) nom_partido = models.CharField(max_length=50) dat_criacao = models.DateField(blank=True, null=True) @@ -38,7 +36,6 @@ class ComposicaoColigacao(models.Model): class Localidade(models.Model): - cod_localidade = models.IntegerField(primary_key=True) nom_localidade = models.CharField(max_length=50, blank=True, null=True) nom_localidade_pesq = models.CharField(max_length=50, blank=True, null=True) tip_localidade = models.CharField(max_length=1, blank=True, null=True) @@ -50,15 +47,13 @@ class NivelInstrucao(models.Model): nivel_instrucao = models.CharField(max_length=50) -class TipoSituacaoMilitar(models.Model): - tip_situacao_militar = models.IntegerField(primary_key=True) +class SituacaoMilitar(models.Model): des_tipo_situacao = models.CharField(max_length=50) class Parlamentar(models.Model): - ### nivel_instrucao = models.ForeignKey(NivelInstrucao, blank=True, null=True) - tip_situacao_militar = models.ForeignKey(TipoSituacaoMilitar, blank=True, null=True) + situacao_militar = models.ForeignKey(SituacaoMilitar, blank=True, null=True) nom_completo = models.CharField(max_length=50) nom_parlamentar = models.CharField(max_length=50, blank=True, null=True) sex_parlamentar = models.CharField(max_length=1) @@ -90,7 +85,6 @@ class TipoDependente(models.Model): class Dependente(models.Model): - cod_dependente = models.AutoField(primary_key=True) tip_dependente = models.ForeignKey(TipoDependente) parlamentar = models.ForeignKey(Parlamentar) nom_dependente = models.CharField(max_length=50) @@ -109,7 +103,6 @@ class Filiacao(models.Model): class TipoAfastamento(models.Model): - tip_afastamento = models.AutoField(primary_key=True) des_afastamento = models.CharField(max_length=50) ind_afastamento = models.IntegerField() ind_fim_mandato = models.IntegerField() @@ -117,9 +110,8 @@ class TipoAfastamento(models.Model): class Mandato(models.Model): - cod_mandato = models.AutoField(primary_key=True) parlamentar = models.ForeignKey(Parlamentar) - tip_afastamento = models.ForeignKey(TipoAfastamento, blank=True, null=True) + tipo_afastamento = models.ForeignKey(TipoAfastamento, blank=True, null=True) legislatura = models.ForeignKey(Legislatura) coligacao = models.ForeignKey(Coligacao, blank=True, null=True) tip_causa_fim_mandato = models.IntegerField(blank=True, null=True) diff --git a/protocoloadm/models.py b/protocoloadm/models.py index 81bb0447f..bb3626d8d 100644 --- a/protocoloadm/models.py +++ b/protocoloadm/models.py @@ -1,10 +1,17 @@ from django.db import models +from materia.models import Autor, TipoMateriaLegislativa + + +class TipoDocumentoAdministrativo(models.Model): + sgl_tipo_documento = models.CharField(max_length=5) + des_tipo_documento = models.CharField(max_length=50) + class DocumentoAcessorioAdministrativo(models.Model): cod_documento_acessorio = models.AutoField(primary_key=True) cod_documento = models.IntegerField() - tip_documento = models.IntegerField() + tipo = models.ForeignKey(TipoDocumentoAdministrativo) nom_documento = models.CharField(max_length=30) nom_arquivo = models.CharField(max_length=100) dat_documento = models.DateField(blank=True, null=True) @@ -15,13 +22,13 @@ class DocumentoAcessorioAdministrativo(models.Model): class DocumentoAdministrativo(models.Model): cod_documento = models.AutoField(primary_key=True) - tip_documento = models.IntegerField() + tipo = models.ForeignKey(TipoDocumentoAdministrativo) num_documento = models.IntegerField() ano_documento = models.SmallIntegerField() dat_documento = models.DateField() num_protocolo = models.IntegerField(blank=True, null=True) txt_interessado = models.CharField(max_length=50, blank=True, null=True) - cod_autor = models.IntegerField(blank=True, null=True) + autor = models.ForeignKey(Autor, blank=True, null=True) num_dias_prazo = models.IntegerField(blank=True, null=True) dat_fim_prazo = models.DateField(blank=True, null=True) ind_tramitacao = models.IntegerField() @@ -39,10 +46,10 @@ class Protocolo(models.Model): tip_protocolo = models.IntegerField() tip_processo = models.IntegerField() txt_interessado = models.CharField(max_length=60, blank=True, null=True) - cod_autor = models.IntegerField(blank=True, null=True) + autor = models.ForeignKey(Autor, blank=True, null=True) txt_assunto_ementa = models.TextField(blank=True, null=True) - tip_documento = models.IntegerField(blank=True, null=True) - tip_materia = models.IntegerField(blank=True, null=True) + tipo_documento = models.ForeignKey(TipoDocumentoAdministrativo, blank=True, null=True) + tipo_materia = models.ForeignKey(TipoMateriaLegislativa, blank=True, null=True) num_paginas = models.IntegerField(blank=True, null=True) txt_observacao = models.TextField(blank=True, null=True) ind_anulado = models.IntegerField() @@ -53,27 +60,19 @@ class Protocolo(models.Model): class StatusTramitacaoAdministrativo(models.Model): - cod_status = models.AutoField(primary_key=True) sgl_status = models.CharField(max_length=10) des_status = models.CharField(max_length=60) ind_fim_tramitacao = models.IntegerField() ind_retorno_tramitacao = models.IntegerField() -class TipoDocumentoAdministrativo(models.Model): - tip_documento = models.AutoField(primary_key=True) - sgl_tipo_documento = models.CharField(max_length=5) - des_tipo_documento = models.CharField(max_length=50) - - class TramitacaoAdministrativo(models.Model): - cod_tramitacao = models.AutoField(primary_key=True) cod_documento = models.IntegerField() dat_tramitacao = models.DateField(blank=True, null=True) cod_unid_tram_local = models.IntegerField(blank=True, null=True) dat_encaminha = models.DateField(blank=True, null=True) cod_unid_tram_dest = models.IntegerField(blank=True, null=True) - cod_status = models.IntegerField(blank=True, null=True) + status = models.ForeignKey(StatusTramitacaoAdministrativo, blank=True, null=True) ind_ult_tramitacao = models.IntegerField() txt_tramitacao = models.TextField(blank=True, null=True) dat_fim_prazo = models.DateField(blank=True, null=True) diff --git a/sessao/models.py b/sessao/models.py index 9cf94ab2a..4b416bb23 100644 --- a/sessao/models.py +++ b/sessao/models.py @@ -7,7 +7,7 @@ from parlamentares.models import CargoMesa, Parlamentar, SessaoLegislativa, Legi class ExpedienteMateria(models.Model): cod_ordem = models.AutoField(primary_key=True) cod_sessao_plen = models.IntegerField() - cod_materia = models.IntegerField() + materia = models.ForeignKey(MateriaLegislativa) dat_ordem = models.DateField() txt_observacao = models.TextField(blank=True, null=True) num_ordem = models.IntegerField()