def _build_one_to_many_input(self, column_name, **kwargs):
        # one to many
        ref_class = self._get_relation_class(column_name)
        ref_obj = ref_class()
        # determine if the model is ordered
        is_ordered = isinstance(ref_obj, Ordered_DB_Model)
        # column name
        custom_label = self.__detail_column_label__[column_name]\
            if column_name in self.__detail_column_label__ else {}
        shown_column = self._get_detail_column_list(column_name)

        # if only one column to be shown and it is a relationship
        if len(shown_column) == 1 and shown_column[0] in ref_obj._get_relation_names():
            input_selector = '#field_' + column_name + '.form-control'
            input_name = column_name+'[]'
            # lookup class is the selection table, while child is association table
            lookup_class = ref_obj._get_relation_class(shown_column[0])
            # get values & options
            values = []
            options = {}
            for child in getattr(self, column_name):
                if isinstance(child, DB_Model):
                    values.append(getattr(child, shown_column[0]).id)
            for lookup in lookup_class.get():
                if isinstance(lookup, DB_Model):
                    options[lookup.id] = lookup.as_text()
            # create combobox
            style = ''
            # ordered
            if is_ordered:
                self.generated_css.append(base_url('assets/multiselect/css/ui.multiselect.css'))
                self.generated_js.append(base_url('assets/multiselect/js/ui.multiselect.js'))
                self.generated_js += self._mutator_js('ordered', 
                        '$("._ordered").multiselect();'
                    )
                input_selector += '._ordered'
                style = 'min-height:150px;'
            # unordered
            else:
                self.generated_css.append(base_url('assets/chosen/chosen.min.css'))
                self.generated_js.append(base_url('assets/chosen/chosen.jquery.min.js'))
                self.generated_js += self._mutator_js('chosen', 
                        '$("._chosen").chosen();'
                    )
                input_selector += '._chosen'
            # create input
            input_element = HTML.select(input_selector, input_name, options, values, True, style = style)
        # else, it must be tabular  
        else:

            ref_obj.generate_tabular_label(state = 'form', shown_column = self._get_detail_column_list(column_name), custom_label = custom_label)
            
            # define several HTML DOM's properties
            div_empty_selector      = '#_div_empty_' + column_name
            div_empty_style         = '' 
            div_control_selector    = '#_div_control_' + column_name
            a_new_selector          = '#_' + column_name + '_add' + '.btn .btn-default ._new_row'
            a_new_caption           = 'New ' + self.build_label(column_name)
            table_selector          = '#_table_' + column_name + '.table'
            table_style             = ''
            tbody_selector          = '#_' + column_name + '_tbody'
            # only one should be shown, table or div_empty
            if len(getattr(self, column_name)) == 0:
                table_style = 'display:none;'
            else:
                div_empty_style = 'display:none;'
                div_control_selector += '.pull-right'

            # div empty
            div_empty   = HTML.div(div_empty_selector, 'No Data', style = div_empty_style)
            # div control
            div_control = HTML.div(div_control_selector, 
                    HTML.a(a_new_selector, '#', HTML.tag('i.glyphicon.glyphicon-plus') + a_new_caption)
                )
            
            # thead
            th = ref_obj.generated_html
            if is_ordered:
                th += HTML.th('Order', style="width:50px;")
            th += HTML.th('Delete', style="width:50px;")
            thead = HTML.thead(HTML.tr(th))

            # tbody
            tr = ''
            new_row_index = 0
            for row_index, child in enumerate(getattr(self, column_name)):
                new_row_index += 1
                child.generate_tabular_input(state = 'form', shown_column = shown_column, parent_column_name = column_name)
                # td
                td = child.generated_html
                # add ordering
                if is_ordered:
                    input_selector  = '._' + column_name + '_index #_' + column_name + '_index_' + str(row_index) 
                    input_name      = '_'+column_name+'_index[]'
                    a_up_selector   = '._' + column_name + '_up'
                    a_down_selector = '._' + column_name + '_down'
                    a_property      = {'row-index' : str(row_index)}
                    td += HTML.td(
                            HTML.input_hidden(input_selector, input_name, str(row_index)) +\
                            HTML.a(a_up_selector, '#', HTML.tag('i.glyphicon.glyphicon-arrow-up'), **a_property ) +\
                            HTML.a(a_down_selector, '#', HTML.tag('i.glyphicon.glyphicon-arrow-down'), **a_property )
                        )
                # add control
                input_id_selector         = '._' + column_name + '_id'
                input_id_name             = '_' + column_name + '_id[]'
                input_deleted_name        = '_' + column_name + '_delete[]'
                checkbox_property         = {'class' : '_' + column_name + '_delete'}
                td += HTML.td(
                        HTML.input_hidden(input_id_selector, input_id_name, str(child.id)) +
                        HTML.input_hidden('.deleted', input_deleted_name, '0') +
                        HTML.label(
                                HTML.input_checkbox(**checkbox_property)
                            )
                    )
                # add to tr
                tr += HTML.tr(td)
            tbody = HTML.tbody(tbody_selector, tr)

            # table
            table = HTML.table(table_selector, thead + tbody, style = table_style)

            # input element
            input_element  = div_empty + div_control + table

            # what should be added when add row clicked
            ref_obj.generate_tabular_input(state = 'form', shown_column = self._get_detail_column_list(column_name), parent_column_name = column_name)
            new_row  = '\'<tr>'
            new_row += ref_obj.generated_html

            # merge detail's css & js into main css & js
            self.generated_js  += ref_obj.generated_js
            self.generated_css += ref_obj.generated_css

            # order column
            last_index_varname = '_' + column_name + '_last_index'
            if is_ordered:
                concat_last_index_varname = '\' + ' + last_index_varname + '+ \''
                new_row += '<td>'
                new_row += '<input class="_'+column_name+'_index" id="_'+column_name+'_index_'+concat_last_index_varname+'" type="hidden" name="_'+column_name+'_index[]" value="'+concat_last_index_varname+'" />'
                new_row += '<a class="_'+column_name+'_up" row-index="'+concat_last_index_varname+'" href="#"><i class="glyphicon glyphicon glyphicon-arrow-up"></i></a>'
                new_row += '<a class="_'+column_name+'_down" row-index="'+concat_last_index_varname+'" href="#"><i class="glyphicon glyphicon glyphicon-arrow-down"></i></a>'
                new_row += '</td>'
            # delete column
            new_row += '<td>'
            new_row += '    <input type="hidden" name="_' + column_name + '_id[]" value="" />'
            new_row += '    <input class="deleted" type="hidden" name="_' + column_name + '_delete[]" value="0" />'
            new_row += '    <label><input type="checkbox" class="_' + column_name + '_delete"></label>'
            new_row += '</td>'
            new_row += '</tr>\''
            script  = ''
            if is_ordered:
                script += 'var ' + last_index_varname + ' = ' + str(new_row_index) + ';'
            # delete event
            script += '$("._' + column_name + '_delete").live("click", function(event){'
            script += '    var input = $(this).parent().parent().children(".deleted");'
            script += '    if($(this).prop("checked")){'
            script += '        input.val("1");'
            script += '    }else{'
            script += '        input.val("0");'
            script += '    }'
            script += '});'
            # add event
            script += '$("#_' + column_name + '_add").click(function(event){'
            script += '    $("#_' + column_name + '_tbody").append(' + new_row + ');'
            script += '    $("#_div_control_' + column_name + '").addClass("pull-right");'
            script += '    $("#_div_empty_' + column_name + '").hide();'
            script += '    $("#_table_' + column_name + '").show();'
            if is_ordered:
                script += '    '+last_index_varname+'++;'
            script += '    event.preventDefault();'
            script += '});'
            # up event
            script += '$("a._'+column_name+'_up").live("click",function(event){'
            script += '    var row_index = $(this).attr("row-index");'
            script += '    var current_tr = $(this).parent().parent();'
            script += '    var prev_tr = current_tr.prev();'
            script += '    if(prev_tr.length > 0){'
            script += '        current_tr.insertBefore(prev_tr);'
            script += '        current_element = current_tr.find("td ._'+column_name+'_index");'
            script += '        prev_element = prev_tr.find("td ._'+column_name+'_index");'
            script += '        current_element_val = current_element.val();'
            script += '        prev_element_val = prev_element.val();'
            script += '        prev_element.val(current_element_val);'
            script += '        current_element.val(prev_element_val);'
            script += '    }'
            script += '    event.preventDefault();'
            script += '});'
            # down event
            script += '$("a._'+column_name+'_down").live("click",function(event){'
            script += '    var row_index = $(this).attr("row-index");'
            script += '    var current_tr = $(this).parent().parent();'
            script += '    var next_tr = current_tr.next();'
            script += '    if(next_tr.length > 0){'
            script += '        current_tr.insertAfter(next_tr);'
            script += '        current_element = current_tr.find("td ._'+column_name+'_index");'
            script += '        next_element = next_tr.find("td ._'+column_name+'_index");'
            script += '        current_element_val = current_element.val();'
            script += '        next_element_val = next_element.val();'
            script += '        next_element.val(current_element_val);'
            script += '        current_element.val(next_element_val);'
            script += '    }'
            script += '    event.preventDefault();'
            script += '});'
            self.generated_js += script
        return input_element
dataset/ETHPy150Open goFrendiAsgard/kokoropy/kokoropy/model.py/DB_Model._build_one_to_many_input/original