From 50a00ad8356dc00abc297bce86791bea02eba204 Mon Sep 17 00:00:00 2001 From: LeandroJatai Date: Sat, 13 Aug 2022 14:36:53 -0300 Subject: [PATCH] Vincula Correspondencia a SessaoPlenaria para suporte m2m --- .../migrations/0066_auto_20220813_1431.py | 25 +++++++++++++++++++ sapl/sessao/models.py | 14 ++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 sapl/sessao/migrations/0066_auto_20220813_1431.py diff --git a/sapl/sessao/migrations/0066_auto_20220813_1431.py b/sapl/sessao/migrations/0066_auto_20220813_1431.py new file mode 100644 index 000000000..9ddde02c6 --- /dev/null +++ b/sapl/sessao/migrations/0066_auto_20220813_1431.py @@ -0,0 +1,25 @@ +# Generated by Django 2.2.28 on 2022-08-13 17:31 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('protocoloadm', '0042_auto_20220805_1236'), + ('sessao', '0065_correspondencia'), + ] + + operations = [ + migrations.AddField( + model_name='sessaoplenaria', + name='correspondencias', + field=models.ManyToManyField(blank=True, related_name='sessoesplenarias', through='sessao.Correspondencia', to='protocoloadm.DocumentoAdministrativo'), + ), + migrations.AlterField( + model_name='correspondencia', + name='sessao_plenaria', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='correspondencia_set', to='sessao.SessaoPlenaria'), + ), + ] diff --git a/sapl/sessao/models.py b/sapl/sessao/models.py index 4b0f04904..e11070a88 100644 --- a/sapl/sessao/models.py +++ b/sapl/sessao/models.py @@ -249,6 +249,17 @@ class SessaoPlenaria(models.Model): choices=YES_NO_CHOICES, verbose_name=_('Publicar Pauta?')) + correspondencias = models.ManyToManyField( + DocumentoAdministrativo, + blank=True, + through='Correspondencia', + related_name='sessoesplenarias', + through_fields=( + 'sessao_plenaria', + 'documento' + ) + ) + class Meta: verbose_name = _('Sessão Plenária') verbose_name_plural = _('Sessões Plenárias') @@ -1029,7 +1040,8 @@ class Correspondencia(models.Model): ) sessao_plenaria = models.ForeignKey(SessaoPlenaria, - on_delete=models.CASCADE) + on_delete=models.CASCADE, + related_name='correspondencia_set') documento = models.ForeignKey(DocumentoAdministrativo, on_delete=models.PROTECT, verbose_name=_('Documento Administrativo'))