def update_payTo(apps, schema_editor):
TransactionParty = apps.get_model('<STR_LIT>', '<STR_LIT>')<EOL>ExpenseItem = apps.get_model('<STR_LIT>', '<STR_LIT>')<EOL>RevenueItem = apps.get_model('<STR_LIT>', '<STR_LIT>')<EOL>GenericRepeatedExpense = apps.get_model('<STR_LIT>', '<STR_LIT>')<EOL>for item in chain(<EOL>ExpenseItem.objects.filter(<EOL>Q(payToUser__isnull=False) | Q(payToLocation__isnull=False) | Q(payToName__isnull=False)<EOL>),<EOL>GenericRepeatedExpense.objects.filter(<EOL>Q(payToUser__isnull=False) | Q(payToLocation__isnull=False) | Q(payToName__isnull=False)<EOL>),<EOL>):<EOL><INDENT>if getattr(item, '<STR_LIT>', None):<EOL><INDENT>party = TransactionParty.objects.get_or_create(<EOL>user=item.payToUser,<EOL>defaults={<EOL>'<STR_LIT:name>': getFullName(item.payToUser),<EOL>'<STR_LIT>': getattr(item.payToUser, '<STR_LIT>', None),<EOL>}<EOL>)[<NUM_LIT:0>]<EOL><DEDENT>elif getattr(item, '<STR_LIT>', None):<EOL><INDENT>party = TransactionParty.objects.get_or_create(<EOL>location=item.payToLocation,<EOL>defaults={<EOL>'<STR_LIT:name>': item.payToLocation.name,<EOL>}<EOL>)[<NUM_LIT:0>]<EOL><DEDENT>elif getattr(item, '<STR_LIT>', None):<EOL><INDENT>party = createPartyFromName(apps, item.payToName)<EOL><DEDENT>item.payTo = party<EOL>item.save()<EOL><DEDENT>for item in RevenueItem.objects.filter(<EOL>Q(receivedFromName__isnull=False)<EOL>):<EOL><INDENT>party = createPartyFromName(apps, item.receivedFromName)<EOL>item.receivedFrom = party<EOL>item.save()<EOL><DEDENT>
With the new TransactionParty model, the senders and recipients of financial
transactions are held in one place.  So, we need to loop through old ExpenseItems,
RevenueItems, and GenericRepeatedExpense and move their old party references
to the new party model.