From 38a1fe12dff8c7a81d2e83283dbc54c91c0c6712 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 10 Jan 2018 16:26:59 +0000 Subject: [PATCH] Add funding to the person model --- .../public/people/migrations/0004_funding.py | 34 +++++++++++++++++++ opentech/public/people/models.py | 27 ++++++++++++++- opentech/public/utils/models.py | 2 +- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 opentech/public/people/migrations/0004_funding.py diff --git a/opentech/public/people/migrations/0004_funding.py b/opentech/public/people/migrations/0004_funding.py new file mode 100644 index 000000000..583eef7f8 --- /dev/null +++ b/opentech/public/people/migrations/0004_funding.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.8 on 2018-01-10 16:25 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import modelcluster.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailcore', '0040_page_draft_title'), + ('people', '0003_update_contact_information'), + ] + + operations = [ + migrations.CreateModel( + name='Funding', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('sort_order', models.IntegerField(blank=True, editable=False, null=True)), + ('value', models.PositiveIntegerField()), + ('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')), + ], + options={ + 'ordering': ['sort_order'], + 'abstract': False, + }, + ), + ] diff --git a/opentech/public/people/models.py b/opentech/public/people/models.py index f002d9e40..3155811a2 100644 --- a/opentech/public/people/models.py +++ b/opentech/public/people/models.py @@ -13,6 +13,7 @@ from wagtail.wagtailadmin.edit_handlers import ( FieldRowPanel, InlinePanel, MultiFieldPanel, + PageChooserPanel, StreamFieldPanel ) from wagtail.wagtailimages.edit_handlers import ImageChooserPanel @@ -71,6 +72,29 @@ class PersonPagePersonType(models.Model): return self.person_type.title +class Funding(Orderable): + page = ParentalKey('PersonPage', related_name='funding') + value = models.PositiveIntegerField() + year = models.PositiveIntegerField() + duration = models.PositiveIntegerField(help_text='In months') + source = models.ForeignKey( + 'wagtailcore.Page', + blank=True, + null=True, + on_delete=models.SET_NULL + ) + + panels = [ + FieldRowPanel([ + FieldPanel('year'), + FieldPanel('value'), + FieldPanel('duration'), + ]), + # This is stubbed as we need to be able to select from multiple + PageChooserPanel('source'), + ] + + class PersonContactInfomation(Orderable): methods = ( ('irc', 'IRC'), @@ -144,7 +168,8 @@ class PersonPage(BasePage): ], heading='Contact information'), InlinePanel('person_types', label='Person types'), FieldPanel('introduction'), - StreamFieldPanel('biography') + StreamFieldPanel('biography'), + InlinePanel('funding', label='Funding'), ] diff --git a/opentech/public/utils/models.py b/opentech/public/utils/models.py index c284e2590..08d72f3bb 100644 --- a/opentech/public/utils/models.py +++ b/opentech/public/utils/models.py @@ -23,7 +23,7 @@ class LinkFields(models.Model): """ link_page = models.ForeignKey( - 'wagtailcore.Page', + 'wagtailcore.FieldPanelPage', blank=True, null=True, on_delete=models.SET_NULL -- GitLab