def _get_form_field(self, field, value=None):
        form_field = None
        if field.field_type == 'text':
            form_field = forms.CharField(label=field.label, max_length=512,
                                         widget=forms.TextInput(attrs={'size': '30'}))
        elif field.field_type == 'details':
            form_field = forms.CharField(
                label=field.label, widget=forms.Textarea())
        elif field.field_type == 'url':
            form_field = forms.URLField(
                label=field.label, widget=forms.TextInput(attrs={'size': '50'}))
        elif field.field_type == 'picture':
            form_field = forms.ImageField(
                label=field.label, widget=forms.FileInput)
        elif field.field_type == 'date':
            form_field = forms.DateTimeField(label=field.label)
            form_field.widget.attrs.update({'class': 'datetimepicker'})
        form_field.required = field.required

        if value:
            if isinstance(form_field, forms.FileField) and value.value:
                form_field = forms.ChoiceField(
                    label=field.label, widget=forms.RadioSelect())
                filename = full_filename = value.value
                match = re.match('.*[a-z0-9]{32}__(?P<filename>.+)$', filename)
                if match:
                    filename = match.group('filename')
                form_field.choices = ((full_filename, _("Keep existing: ") + unicode(filename)),
                                      ('delete', _("Delete ")))
                form_field.initial = full_filename
                form_field.required = False
            else:
                form_field.initial = value.value

        return form_field
Generate a Django-friendly field from Hardtree spec in DB
dataset/ETHPy150Open treeio/treeio/treeio/infrastructure/forms.py/ItemForm._get_form_field