Skip to content

Commit

Permalink
change industries_worked to m2m field
Browse files Browse the repository at this point in the history
  • Loading branch information
frdrckaman committed Sep 15, 2022
1 parent bc1eb2b commit 0615303
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 15 deletions.
12 changes: 12 additions & 0 deletions edcs_lists/list_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@
(OTHER, "Others"),
(NONE_OF_ABOVE, "None of the above"),
],
"edcs_lists.industries": [
(NOT_APPLICABLE, "Not applicable"),
("textile_industry", "Textile industry"),
("chemical_production_industry", "Chemical production industry"),
("food_processing_industry", "Food processing industry"),
("drug_industry", "Drug industry"),
("milling_industry", "Milling industry"),
("construction_industry", "Construction industry"),
("gas_fuel_stations", "Gas / fuel stations"),
("cement_industry", "Cement industry"),
(OTHER, "Other"),
],
}

# preload_data = PreloadData(list_data=list_data)
35 changes: 35 additions & 0 deletions edcs_lists/migrations/0008_auto_20220915_0311.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.1.7 on 2022-09-15 03:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('edcs_lists', '0007_auto_20220913_1726'),
]

operations = [
migrations.CreateModel(
name='Industries',
fields=[
('name', models.CharField(db_index=True, help_text='This is the stored value, required', max_length=250, unique=True, verbose_name='Stored value')),
('display_name', models.CharField(db_index=True, help_text='(suggest 40 characters max.)', max_length=250, unique=True, verbose_name='Name')),
('display_index', models.IntegerField(db_index=True, default=0, help_text='Index to control display order if not alphabetical, not required', verbose_name='display index')),
('field_name', models.CharField(blank=True, editable=False, help_text='Not required', max_length=25, null=True)),
('version', models.CharField(default='1.0', editable=False, max_length=35)),
('id', models.AutoField(primary_key=True, serialize=False)),
],
options={
'verbose_name': 'Industries',
'verbose_name_plural': 'Industries',
'ordering': ['display_index', 'display_name'],
'abstract': False,
'default_permissions': ('add', 'change', 'delete', 'view', 'export', 'import'),
},
),
migrations.AddIndex(
model_name='industries',
index=models.Index(fields=['id', 'display_name', 'display_index'], name='edcs_lists__id_67713f_idx'),
),
]
6 changes: 6 additions & 0 deletions edcs_lists/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,9 @@ class CancerInvestigation(ListModelMixin):
class Meta(ListModelMixin.Meta):
verbose_name = "Cancer Investigation"
verbose_name_plural = "Cancer Investigation"


class Industries(ListModelMixin):
class Meta(ListModelMixin.Meta):
verbose_name = "Industries"
verbose_name_plural = "Industries"
13 changes: 6 additions & 7 deletions edcs_subject/admin/occupational_history_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from edcs_crf.admin import crf_status_fieldset_tuple
from edcs_model_admin import SimpleHistoryAdmin

from .modeladmin_mixins import CrfModelAdminMixin
from ..admin_site import edcs_subject_admin
from ..forms import OccupationalHistoryForm
from ..models import OccupationalHistory
from .modeladmin_mixins import CrfModelAdminMixin


@admin.register(OccupationalHistory, site=edcs_subject_admin)
Expand Down Expand Up @@ -37,7 +37,6 @@ class OccupationalHistoryAdmin(CrfModelAdminMixin, SimpleHistoryAdmin):
list_display = (
"report_datetime",
"history_working_industries",
"industries_worked",
"history_working_mines",
"how_long_work_mine",
"activities_expose_to_smoke",
Expand All @@ -47,19 +46,19 @@ class OccupationalHistoryAdmin(CrfModelAdminMixin, SimpleHistoryAdmin):
list_filter = (
"report_datetime",
"history_working_industries",
"industries_worked",
"history_working_mines",
"how_long_work_mine",
"activities_expose_to_smoke",
)

search_fields = (
"report_datetime",
)
search_fields = ("report_datetime",)

filter_horizontal = [
"industries_worked",
]

radio_fields = {
"history_working_industries": admin.VERTICAL,
"industries_worked": admin.VERTICAL,
"history_working_mines": admin.VERTICAL,
"how_long_work_mine": admin.VERTICAL,
"crf_status": admin.VERTICAL,
Expand Down
4 changes: 2 additions & 2 deletions edcs_subject/forms/occupational_history_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def clean(self):
field="history_working_industries",
field_applicable="industries_worked",
)
self.required_if(
OTHER, field="industries_worked", field_required="industries_worked_other"
self.m2m_other_specify(
OTHER, m2m_field="industries_worked", field_other="industries_worked_other"
)
self.applicable_if(
YES, field="history_working_mines", field_applicable="how_long_work_mine"
Expand Down
27 changes: 27 additions & 0 deletions edcs_subject/migrations/0040_auto_20220915_0311.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.1.7 on 2022-09-15 03:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('edcs_lists', '0008_auto_20220915_0311'),
('edcs_subject', '0039_auto_20220915_0242'),
]

operations = [
migrations.RemoveField(
model_name='historicaloccupationalhistory',
name='industries_worked',
),
migrations.RemoveField(
model_name='occupationalhistory',
name='industries_worked',
),
migrations.AddField(
model_name='occupationalhistory',
name='industries_worked',
field=models.ManyToManyField(to='edcs_lists.Industries', verbose_name='If yes, what kind of industry did you work?'),
),
]
11 changes: 5 additions & 6 deletions edcs_subject/models/occupational_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from edcs_constants.choices import YES_NO_DECLINED_TO_ANSWER
from edcs_constants.constants import NOT_APPLICABLE
from edcs_lists.models import Industries
from edcs_model import models as edcs_models
from edcs_utils import get_utcnow

from ..model_mixins import CrfModelMixin
from ..choices import QN65, QN72
from ..model_mixins import CrfModelMixin


class OccupationalHistory(CrfModelMixin, edcs_models.BaseUuidModel):
Expand All @@ -22,11 +23,9 @@ class OccupationalHistory(CrfModelMixin, edcs_models.BaseUuidModel):
choices=YES_NO_DECLINED_TO_ANSWER,
)

industries_worked = models.CharField(
industries_worked = models.ManyToManyField(
Industries,
verbose_name="If yes, what kind of industry did you work?",
max_length=45,
choices=QN72,
default=NOT_APPLICABLE
)

industries_worked_other = edcs_models.OtherCharField()
Expand All @@ -41,7 +40,7 @@ class OccupationalHistory(CrfModelMixin, edcs_models.BaseUuidModel):
verbose_name="If yes, for how long have worked in the mines?",
max_length=45,
choices=QN65,
default=NOT_APPLICABLE
default=NOT_APPLICABLE,
)

activities_expose_to_smoke = models.TextField(
Expand Down

0 comments on commit 0615303

Please sign in to comment.