Skip to content

Commit

Permalink
fix: IndicatorPeriod.get_root_period() not available in migrations
Browse files Browse the repository at this point in the history
The function was copy-pasted from the model class for the migration
 because apps.get_model() can't make model methods available.

#5145: Feature Request: UI for aggregation tasks
  • Loading branch information
MichaelAkvo committed Nov 8, 2022
1 parent 9f6de5d commit 89e2da2
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
import django.db.models.deletion


def get_root_period(period):
root = period
while root.parent_period:
root = root.parent_period
return root


def set_root_period(apps, schema_editor):
IndicatorPeriodAggregationJob = apps.get_model("rsr", "IndicatorPeriodAggregationJob")
jobs = []
for job in IndicatorPeriodAggregationJob.objects.all():
job.root_period = job.period.get_root_period()
job.root_period = get_root_period(job.period)
jobs.append(job)
IndicatorPeriodAggregationJob.objects.bulk_update(jobs, ["root_period"])

Expand Down

0 comments on commit 89e2da2

Please sign in to comment.