<gh_stars>1-10
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2017-04-05 21:13
from __future__ import unicode_literals

from django.db import migrations
from django.db.models import F

from usaspending_api.financial_activities.models import TasProgramActivityObjectClassQuarterly


def forwards_or_backwards_func(apps, schema_editor):
    """
    Because -1 * -1 == 1, this migration works the same both directions!
    """
    db_alias = schema_editor.connection.alias

    cls = apps.get_model('financial_activities', 'FinancialAccountsByProgramActivityObjectClass')

    # invert values of all fields ending in _cpe or _fyb
    updates = {field_name: F(field_name) * -1
               for field_name in dir(cls) if (
                   field_name.endswith('_cpe') or field_name.endswith('_fyb'))}
    cls.objects.using(db_alias).update(**updates)

    # re-calculate all TasProgramActivityObjectClassQuarterly numbers
    # to ensure that they match the signs of the underlying
    # FinancialAccountsByProgramActivityObjectClass data
    TasProgramActivityObjectClassQuarterly.insert_quarterly_numbers()


class Migration(migrations.Migration):

    dependencies = [
        ('financial_activities', '0020_insert_tas_oc_pa_quarterly'),
    ]

    operations = [
        migrations.RunPython(forwards_or_backwards_func,
                             forwards_or_backwards_func),
    ]

# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2017-04-05 21:13
from __future__ import unicode_literals

from django.db import migrations
from django.db.models import F

from usaspending_api.financial_activities.models import TasProgramActivityObjectClassQuarterly


def forwards_or_backwards_func(apps, schema_editor):
    """
    Because -1 * -1 == 1, this migration works the same both directions!
    """
    db_alias = schema_editor.connection.alias

    cls = apps.get_model('financial_activities', 'FinancialAccountsByProgramActivityObjectClass')

    # invert values of all fields ending in _cpe or _fyb
    updates = {field_name: F(field_name) * -1
               for field_name in dir(cls) if (
                   field_name.endswith('_cpe') or field_name.endswith('_fyb'))}
    cls.objects.using(db_alias).update(**updates)

    # re-calculate all TasProgramActivityObjectClassQuarterly numbers
    # to ensure that they match the signs of the underlying
    # FinancialAccountsByProgramActivityObjectClass data
    TasProgramActivityObjectClassQuarterly.insert_quarterly_numbers()


class Migration(migrations.Migration):

    dependencies = [
        ('financial_activities', '0020_insert_tas_oc_pa_quarterly'),
    ]

    operations = [
        migrations.RunPython(forwards_or_backwards_func,
                             forwards_or_backwards_func),
    ]
# -*- coding: utf-8 -*- # Generated by Django 1.10.1 on 2017-04-05 21:13 Because -1 * -1 == 1, this migration works the same both directions! # invert values of all fields ending in _cpe or _fyb # re-calculate all TasProgramActivityObjectClassQuarterly numbers # to ensure that they match the signs of the underlying # FinancialAccountsByProgramActivityObjectClass data