def createPartyFromName(apps, name):
    '''
    For creating/matching TransactionParty objects using names alone.
    Look for staff members with the same name and match to them first if there is
    exactly one match.  Then, look for users and match them if there is exactly one
    match. Otherwise, just generate a TransactionParty for the name only.
    '''

    TransactionParty = apps.get_model('financial', 'TransactionParty')
    StaffMember = apps.get_model('core', 'StaffMember')
    User = apps.get_model('auth', 'User')

    firstName = name.split(' ')[0]
    lastName = ' '.join(name.split(' ')[1:])

    members = StaffMember.objects.filter(
        firstName__istartswith=firstName, lastName__istartswith=lastName
    )
    users = User.objects.filter(
        first_name__istartswith=firstName, last_name__istartswith=lastName
    )

    if members.count() == 1:
        this_member = members.first()
        party = TransactionParty.objects.get_or_create(
            staffMember=this_member,
            defaults={
                'name': getFullName(this_member),
                'user': this_member.userAccount,
            }
        )[0]
    elif users.count() == 1:
        this_user = users.first()
        party = TransactionParty.objects.get_or_create(
            user=this_user,
            defaults={
                'name': getFullName(this_user),
                'staffMember': getattr(this_user, 'staffmember', None),
            }
        )[0]
    else:
        party = TransactionParty.objects.get_or_create(
            name=name
        )[0]
    return party
For creating/matching TransactionParty objects using names alone.
    Look for staff members with the same name and match to them first if there is
    exactly one match.  Then, look for users and match them if there is exactly one
    match. Otherwise, just generate a TransactionParty for the name only.