Skip to content

Commit

Permalink
Field reports figures into separate table
Browse files Browse the repository at this point in the history
  • Loading branch information
szabozoltan69 committed Nov 3, 2022
1 parent a686800 commit 05f7f37
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
26 changes: 26 additions & 0 deletions api/migrations/0161_figure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 3.2.16 on 2022-11-03 15:15

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


class Migration(migrations.Migration):

dependencies = [
('api', '0160_merge_0159_auto_20221022_1542_0159_auto_20221028_0940'),
]

operations = [
migrations.CreateModel(
name='Figure',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('type', models.IntegerField(choices=[(0, 'Unknown'), (1, 'Affected'), (2, 'Potentially affected'), (3, 'Assisted'), (4, 'Dead'), (5, 'Displaced'), (6, 'Highest risk'), (7, 'Injured'), (8, 'Missing')], default=1, help_text='Type of figure', verbose_name='type')),
('source', models.IntegerField(choices=[(1, 'Red Cross / Red Crescent'), (2, 'Government'), (3, 'Global Crisis Data Bank'), (4, 'UN'), (5, 'Other')], default=1, help_text='Source of figure', verbose_name='source')),
('value', models.IntegerField(default=0, verbose_name='number of beneficiaries')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='created at')),
('modified_at', models.DateTimeField(auto_now=True, verbose_name='modified at')),
('field_report', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.fieldreport', verbose_name='Field report')),
],
),
]
34 changes: 33 additions & 1 deletion api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,6 @@ class Meta:
verbose_name_plural = _('Regional Admins')

def __str__(self):
# import pdb; pdb.set_trace();
return self.user.get_username()


Expand Down Expand Up @@ -1432,6 +1431,39 @@ def __str__(self):
return '%s: %s' % (self.name, self.title)


@reversion.register()
class Figure(models.Model):
""" num_affected, _missing, _dead etc. figure linked to field report """

class FigureType(models.IntegerChoices):
UNKNOWN = 0, _('Unknown')
AFFECTED = 1, _('Affected')
P_AFFECTED = 2, _('Potentially affected')
ASSISTED = 3, _('Assisted')
DEAD = 4, _('Dead')
DISPLACED = 5, _('Displaced')
HIGHEST_RISK = 6, _('Highest risk')
INJURED = 7, _('Injured')
MISSING = 8, _('Missing')

class FigureSource(models.IntegerChoices):
RC = 1, _('Red Cross / Red Crescent')
GOV = 2, _('Government')
GCDB = 3, _('Global Crisis Data Bank')
UN = 4, _('UN')
OTHER = 5, _('Other')

field_report = models.ForeignKey(FieldReport, verbose_name=_('Field report'), on_delete=models.CASCADE)
type = models.IntegerField(choices=FigureType.choices, verbose_name=_('type'), default=1, help_text=_('Type of figure'))
source = models.IntegerField(choices=FigureSource.choices, verbose_name=_('source'), default=1, help_text=_('Source of figure'))
value = models.IntegerField(verbose_name=_('value'), default=0)
created_at = models.DateTimeField(verbose_name=_('created at'), auto_now_add=True)
modified_at = models.DateTimeField(verbose_name=_('modified at'), auto_now=True)

def __str__(self):
return "%s (%s)" % (self.get_type_display(), self.get_source_display())


class ActionOrg(models.TextChoices):
NATIONAL_SOCIETY = 'NTLS', _('National Society')
FOREIGN_SOCIETY = 'PNS', _('RCRC')
Expand Down

0 comments on commit 05f7f37

Please sign in to comment.