Skip to content

Commit

Permalink
Merge pull request #1094 from jefmoura/261-add-dissagregation-validation
Browse files Browse the repository at this point in the history
Add some field validations in disaggregations
  • Loading branch information
Rafael Muñoz Cárdenas authored May 14, 2018
2 parents d6929c2 + c51ff1c commit 6d63b51
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
11 changes: 11 additions & 0 deletions factories/indicators_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ def workflowlevel1(self, create, extracted, **kwargs):
for workflowlevel1 in extracted:
self.workflowlevel1.add(workflowlevel1)

@post_generation
def disaggregation(self, create, extracted, **kwargs):
if not create:
# Simple build, do nothing.
return

if extracted:
# A list of disaggregation were passed in, use them
for disaggregation in extracted:
self.disaggregation.add(disaggregation)


class Objective(DjangoModelFactory):
class Meta:
Expand Down
26 changes: 26 additions & 0 deletions indicators/migrations/0009_auto_20180509_0140.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2018-05-09 08:40
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('indicators', '0008_disaggregationvalue_indicator'),
]

operations = [
migrations.AlterField(
model_name='disaggregationlabel',
name='disaggregation_type',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='indicators.DisaggregationType'),
),
migrations.AlterField(
model_name='disaggregationvalue',
name='disaggregation_label',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='indicators.DisaggregationLabel'),
),
]
4 changes: 2 additions & 2 deletions indicators/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class DisaggregationTypeAdmin(admin.ModelAdmin):


class DisaggregationLabel(models.Model):
disaggregation_type = models.ForeignKey(DisaggregationType)
disaggregation_type = models.ForeignKey(DisaggregationType, on_delete=models.deletion.PROTECT)
label = models.CharField(max_length=765, blank=True)
customsort = models.IntegerField(blank=True, null=True)
create_date = models.DateTimeField(null=True, blank=True)
Expand All @@ -210,7 +210,7 @@ def save(self, *args, **kwargs):


class DisaggregationValue(models.Model):
disaggregation_label = models.ForeignKey(DisaggregationLabel)
disaggregation_label = models.ForeignKey(DisaggregationLabel, on_delete=models.deletion.PROTECT)
indicator = models.ForeignKey('indicators.Indicator', null=True, blank=True)
value = models.CharField(max_length=765, blank=True)
create_date = models.DateTimeField(null=True, blank=True)
Expand Down

0 comments on commit 6d63b51

Please sign in to comment.