'Handle a <field> node for a ForeignKey'

def _handle_fk_field_node(self, node, field):

    if node.getElementsByTagName(u'None'):
        return None
    elif hasattr(field.rel.to._default_manager, u'get_by_natural_key'):
        keys = node.getElementsByTagName(u'natural')
        if keys:
            field_value = [getInnerText(k).strip() for k in keys]
            obj = field.rel.to._default_manager.db_manager(self.db).get_by_natural_key(*field_value)
            obj_pk = getattr(obj, field.rel.field_name)
            if field.rel.to._meta.pk.rel:
                obj_pk = obj_pk.pk
        else:
            field_value = getInnerText(node).strip()
            obj_pk = field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value)
        return obj_pk
    else:
        field_value = getInnerText(node).strip()
        return field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value)
