Allow CorpContact.corporation being null
This commit is contained in:
parent
c4c7ec5c79
commit
0a9ecd8c96
3 changed files with 23 additions and 3 deletions
16
stages/migrations/0009_corpcontact_corp_nullable.py
Normal file
16
stages/migrations/0009_corpcontact_corp_nullable.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stages', '0008_add_logbook'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='corpcontact',
|
||||
name='corporation',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=models.deletion.CASCADE, to='stages.Corporation', verbose_name='Institution'),
|
||||
),
|
||||
]
|
||||
|
|
@ -311,7 +311,10 @@ class Corporation(models.Model):
|
|||
|
||||
|
||||
class CorpContact(models.Model):
|
||||
corporation = models.ForeignKey(Corporation, verbose_name='Institution', on_delete=models.CASCADE)
|
||||
corporation = models.ForeignKey(
|
||||
Corporation, verbose_name='Institution', null=True, blank=True,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
ext_id = models.IntegerField(null=True, blank=True, verbose_name='ID externe')
|
||||
is_main = models.BooleanField(default=False, verbose_name='Contact principal')
|
||||
always_cc = models.BooleanField(default=False, verbose_name='Toujours en copie')
|
||||
|
|
@ -328,7 +331,7 @@ class CorpContact(models.Model):
|
|||
verbose_name = "Contact"
|
||||
|
||||
def __str__(self):
|
||||
return '{0} {1}, {2}'.format(self.last_name, self.first_name, self.corporation)
|
||||
return '{0} {1}, {2}'.format(self.last_name, self.first_name, self.corporation or '-')
|
||||
|
||||
|
||||
class Domain(models.Model):
|
||||
|
|
|
|||
|
|
@ -751,7 +751,8 @@ def stages_export(request, scope=None):
|
|||
(c, {s: [] for s in section_names})
|
||||
for c in Corporation.objects.all().values_list('name', flat=True)
|
||||
)
|
||||
for contact in CorpContact.objects.all().select_related('corporation'
|
||||
for contact in CorpContact.objects.filter(corporation__isnull=False
|
||||
).select_related('corporation'
|
||||
).prefetch_related('sections').order_by('corporation'):
|
||||
for section in contact.sections.all():
|
||||
if not default_contacts[contact.corporation.name][section.name] or contact.is_main is True:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue