(form)
return dict
Create a dictionary from the input form. The dictionary can be used with
    handsontable to populate column/row headers and other configuration data.

    Args:
        form: The Django form objects to convert to a dictionary

    Returns:
        Returns an array of dictionaries from the input form. Includes the
        following keys in the dictionary:

            classes: The classes that will be in the Django widget's "class"
                attribute. These classes values will show up in the form's
                HTML input elements
            choices: An array of choices for fields that have a set
                list of choices
            initial: The initial value of the field, if specified
            isRequired: A boolean indicating if the field is required
                by the form
            label: The human readable displayed string identifying the field
            name: The name of the member variable for the field in the form
            position: The relative position of the field compared to other
                fields in the same form
            type: The type of the field (e.g. choice, text, checkbox)
            value: The value of the field, if specified
Create a dictionary from the input form. The dictionary can be used with
    handsontable to populate column/row headers and other configuration data.
Create a dictionary from the input form . The dictionary can be used with handsontable to populate column / row headers and other configuration data .
def form_to_dict(form):
    """
    Create a dictionary from the input form. The dictionary can be used with
    handsontable to populate column/row headers and other configuration data.

    Args:
        form: The Django form objects to convert to a dictionary

    Returns:
        Returns an array of dictionaries from the input form. Includes the
        following keys in the dictionary:

            classes: The classes that will be in the Django widget's "class"
                attribute. These classes values will show up in the form's
                HTML input elements
            choices: An array of choices for fields that have a set
                list of choices
            initial: The initial value of the field, if specified
            isRequired: A boolean indicating if the field is required
                by the form
            label: The human readable displayed string identifying the field
            name: The name of the member variable for the field in the form
            position: The relative position of the field compared to other
                fields in the same form
            type: The type of the field (e.g. choice, text, checkbox)
            value: The value of the field, if specified
    """

    dict = []

    # need an offset to account for skipped fields
    offset = 0;

    for position, field in enumerate(form):
        newItem = {'name': field.name,
                   'position': position + offset,
                   'label': field.label,
                   'value': field.value,
                   'initial': field.field.initial}
        newItem['isRequired'] = field.field.required

        classes = field.field.widget.attrs.get('class')
        if classes != None:
            if "bulkskip" not in classes:
                newItem['classes'] = classes.split()

                if "bulknoinitial" in newItem['classes']:
                    newItem['initial'] = None;
            else:
                offset -= 1
                continue;

        if isinstance(field.field, ExtendedChoiceField):
            newItem['type'] = 'choice'
            newItem['choices'] = []
            for key,value,attr in field.field.choices:
                newItem['choices'].append({"key": key, "attr": attr})
        elif isinstance(field.field, forms.ChoiceField):
            newItem['type'] = 'choice'
            newItem['choices'] = []
            for key,value in field.field.choices:
                newItem['choices'].append(key)
        elif isinstance(field.field, forms.CharField):
            newItem['type'] = 'text'
        elif isinstance(field.field, forms.BooleanField):
            newItem['type'] = 'checkbox'
        elif isinstance(field.field, forms.DateTimeField):
            #newItem['type'] = 'date'
            newItem['type'] = 'text'
        elif isinstance(field.field, forms.GenericIPAddressField):
            newItem['type'] = 'text'
        else:
            newItem['type'] = 'text'

        dict.append(newItem)

    return dict
def form_to_dict ( form ) : dict = [ ] # need an offset to account for skipped fields offset = 0 for position , field in enumerate ( form ) : newItem = { 'name' : field . name , 'position' : position + offset , 'label' : field . label , 'value' : field . value , 'initial' : field . field . initial } newItem [ 'isRequired' ] = field . field . required classes = field . field . widget . attrs . get ( 'class' ) if classes != None : if "bulkskip" not in classes : newItem [ 'classes' ] = classes . split ( ) if "bulknoinitial" in newItem [ 'classes' ] : newItem [ 'initial' ] = None else : offset -= 1 continue if isinstance ( field . field , ExtendedChoiceField ) : newItem [ 'type' ] = 'choice' newItem [ 'choices' ] = [ ] for key , value , attr in field . field . choices : newItem [ 'choices' ] . append ( { "key" : key , "attr" : attr } ) elif isinstance ( field . field , forms . ChoiceField ) : newItem [ 'type' ] = 'choice' newItem [ 'choices' ] = [ ] for key , value in field . field . choices : newItem [ 'choices' ] . append ( key ) elif isinstance ( field . field , forms . CharField ) : newItem [ 'type' ] = 'text' elif isinstance ( field . field , forms . BooleanField ) : newItem [ 'type' ] = 'checkbox' elif isinstance ( field . field , forms . DateTimeField ) : #newItem['type'] = 'date' newItem [ 'type' ] = 'text' elif isinstance ( field . field , forms . GenericIPAddressField ) : newItem [ 'type' ] = 'text' else : newItem [ 'type' ] = 'text' dict . append ( newItem ) return dict