

def formfield_for_document_field(document, field_name, form_class=forms.CharField, **kwargs):
    field_type = get_field_type_from_document(document, field_name)
    FormField = get_default_form_field_types(document, field_name, field_type)
    defaults = {
        'required': (field_name in document.required_fields),
    }
    if (field_type == list):
        defaults['initial'] = '[]'
    if (field_type == dict):
        defaults['initial'] = '{}'
    if (field_name in document.default_values):
        default_value = document.default_values[field_name]
        if callable(default_value):
            default_value = default_value()
        defaults['initial'] = default_value
    defaults.update(kwargs)
    formfield = FormField(**defaults)
    return formfield

dataset/ETHPy150Open peterbe/django-mongokit/django_mongokit/forms/forms.py formfield_for_document_field/original