diff --git a/opentech/public/people/migrations/0004_funding.py b/opentech/public/people/migrations/0004_funding.py index 583eef7f80badf26f89b09ddbbec763dc8ac42f4..55de7f9893f22efa21be3836d0b621a1faab9e01 100644 --- a/opentech/public/people/migrations/0004_funding.py +++ b/opentech/public/people/migrations/0004_funding.py @@ -24,7 +24,7 @@ class Migration(migrations.Migration): ('year', models.PositiveIntegerField()), ('duration', models.PositiveIntegerField(help_text='In months')), ('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='funding', to='people.PersonPage')), - ('source', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='wagtailcore.Page')), + ('source', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='wagtailcore.Page')), ], options={ 'ordering': ['sort_order'], diff --git a/opentech/public/people/models.py b/opentech/public/people/models.py index 3155811a25173f4dee0538c20d493f4798c0fe25..04ca3f7e421fe7380951e0e72634b90ed310f7b5 100644 --- a/opentech/public/people/models.py +++ b/opentech/public/people/models.py @@ -79,9 +79,7 @@ class Funding(Orderable): duration = models.PositiveIntegerField(help_text='In months') source = models.ForeignKey( 'wagtailcore.Page', - blank=True, - null=True, - on_delete=models.SET_NULL + on_delete=models.PROTECT, ) panels = [ @@ -172,6 +170,10 @@ class PersonPage(BasePage): InlinePanel('funding', label='Funding'), ] + @property + def total_funding(self): + return sum(funding.value for funding in self.funding.all()) + class PersonIndexPage(BasePage): subpage_types = ['PersonPage'] diff --git a/opentech/public/people/templates/people/person_page.html b/opentech/public/people/templates/people/person_page.html index d06d83f2e19f282f525fc592191abfc3b98c71c2..bdffcff4eb6d46cea2048091e278a5ba5f325db6 100644 --- a/opentech/public/people/templates/people/person_page.html +++ b/opentech/public/people/templates/people/person_page.html @@ -52,6 +52,18 @@ <h3>{{ item.get_service_display }}</h3> <p>{{ item.profile_url }}</p> {% endfor %} + <h2>Funding to date</h2> + {% for funding in page.funding.all %} + <table> + <tr> + <td>{{ funding.year }}</td> + <td>${{ funding.value }}</td> + <td>{{ funding.duration }} months</td> + <td><a href="{% pageurl funding.source %}">{{ funding.source }}</a></td> + </tr> + </table> + {% endfor %} + <p>Total FUnding: {{ page.total_funding }}</p> </div> </section>