diff --git a/sapl/base/migrations/0019_auto_20180815_1025.py b/sapl/base/migrations/0019_auto_20180815_1025.py new file mode 100644 index 000000000..e96759e52 --- /dev/null +++ b/sapl/base/migrations/0019_auto_20180815_1025.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.13 on 2018-08-15 13:25 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0018_auto_20180801_1652'), + ] + + operations = [ + migrations.AlterField( + model_name='autor', + name='tipo', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='base.TipoAutor', verbose_name='Tipo do Autor'), + ), + ] diff --git a/sapl/base/models.py b/sapl/base/models.py index fbfadd835..df8ae7c3f 100644 --- a/sapl/base/models.py +++ b/sapl/base/models.py @@ -5,6 +5,7 @@ from django.db import models from django.db.models.signals import post_migrate from django.db.utils import DEFAULT_DB_ALIAS from django.utils.translation import ugettext_lazy as _ + from sapl.utils import (LISTA_DE_UFS, YES_NO_CHOICES, get_settings_auth_user_model, models_with_gr_for_model) @@ -178,7 +179,8 @@ class Autor(models.Model): on_delete=models.SET_NULL, null=True) - tipo = models.ForeignKey(TipoAutor, verbose_name=_('Tipo do Autor')) + tipo = models.ForeignKey(TipoAutor, verbose_name=_('Tipo do Autor'), + on_delete=models.PROTECT) content_type = models.ForeignKey( ContentType, @@ -199,23 +201,17 @@ class Autor(models.Model): ordering = ('nome',) def __str__(self): - if self.autor_related: return str(self.autor_related) else: - if str(self.cargo): - return _('%(nome)s - %(cargo)s') % { - 'nome': self.nome, 'cargo': self.cargo} - else: - return str(self.nome) - """if str(self.tipo) == 'Parlamentar' and self.parlamentar: - return self.parlamentar.nome_parlamentar - elif str(self.tipo) == 'Comissao' and self.comissao: - return str(self.comissao) - elif str(self.tipo) == 'Partido' and self.partido: - return str(self.partido) - else: - """ + if self.nome: + if self.cargo: + return '{} - {}'.format(self.nome, self.cargo) + else: + return str(self.nome) + if self.user: + return str(self.user.username) + return '?' def cria_models_tipo_autor(app_config=None, verbosity=2, interactive=True, diff --git a/sapl/crud/base.py b/sapl/crud/base.py index 8bb8c3794..739fc4f37 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -851,7 +851,9 @@ class CrudDeleteView(PermissionRequiredContainerCrudMixin, é referenciado por outros registros:
\ ' messages.add_message(request,