diff --git a/opentech/apply/funds/migrations/0005_applicationsubmission.py b/opentech/apply/funds/migrations/0005_applicationsubmission.py index f2c19d9242a04455f0cd87b0070717a8de7e31c2..ac820aae9eaf15fbd2148a022f554c4c8de8ff4c 100644 --- a/opentech/apply/funds/migrations/0005_applicationsubmission.py +++ b/opentech/apply/funds/migrations/0005_applicationsubmission.py @@ -2,6 +2,7 @@ # Generated by Django 1.11.8 on 2018-01-22 09:40 from __future__ import unicode_literals +import django.contrib.postgres.fields.jsonb from django.db import migrations, models import django.db.models.deletion @@ -18,7 +19,7 @@ class Migration(migrations.Migration): name='ApplicationSubmission', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('form_data', models.TextField()), + ('form_data', django.contrib.postgres.fields.jsonb.JSONField()), ('submit_time', models.DateTimeField(auto_now_add=True, verbose_name='submit time')), ('page', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='wagtailcore.Page')), ], diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py index cbedf7486caef4692c8a6628031663c3896dea28..9c0b275009dcb2932e085afe214326b9f5ed420d 100644 --- a/opentech/apply/funds/models.py +++ b/opentech/apply/funds/models.py @@ -1,6 +1,7 @@ from datetime import date from django.core.exceptions import ValidationError +from django.contrib.postgres.fields import JSONField from django.db import models from django.db.models import Q from django.http import Http404 @@ -56,6 +57,13 @@ class FundType(AbstractStreamForm): def get_submission_class(self): return ApplicationSubmission + def process_form_submission(self, form): + # Handle passing to JSONField + return self.get_submission_class().objects.create( + form_data=form.cleaned_data, + page=self, + ) + @property def workflow_class(self): return WORKFLOW_CLASS[self.get_workflow_display()] @@ -189,8 +197,22 @@ class Round(AbstractStreamForm): class ApplicationSubmission(AbstractFormSubmission): + form_data = JSONField() + + def get_data(self): + # Updated for JSONField + form_data = self.form_data + form_data.update({ + 'submit_time': self.submit_time, + }) + + return form_data + def __getattr__(self, item): # fall back to values defined on the data if item in REQUIRED_BLOCK_NAMES: return self.get_data()[item] return super().__getattr__(item) + + def __str__(self): + return str(super().__str__())