def __init__(self, form, context, *args, **kwargs):
    '\n        Dynamically add each of the form fields for the given form model\n        instance and its related field model instances.\n        '
    self.form = form
    self.form_fields = form.fields.visible()
    initial = kwargs.pop('initial', {})
    field_entries = {}
    if kwargs.get('instance'):
        for field_entry in kwargs['instance'].fields.all():
            field_entries[field_entry.field_id] = field_entry.value
    super(FormForForm, self).__init__(*args, **kwargs)
    for field in self.form_fields:
        field_key = ('field_%s' % field.id)
        field_class = fields.CLASSES[field.field_type]
        field_widget = fields.WIDGETS.get(field.field_type)
        field_args = {'label': field.label, 'required': field.required, 'help_text': field.help_text}
        if (field.required and (not field.help_text)):
            field_args['help_text'] = _('required')
        arg_names = field_class.__init__.__code__.co_varnames
        if ('max_length' in arg_names):
            field_args['max_length'] = settings.FORMS_FIELD_MAX_LENGTH
        if ('choices' in arg_names):
            choices = list(field.get_choices())
            if ((field.field_type == fields.SELECT) and (field.default not in [c[0] for c in choices])):
                choices.insert(0, ('', field.placeholder_text))
            field_args['choices'] = choices
        if (field_widget is not None):
            field_args['widget'] = field_widget
        initial_val = None
        try:
            initial_val = field_entries[field.id]
        except KeyError:
            try:
                initial_val = initial[field_key]
            except KeyError:
                initial_val = Template(field.default).render(context)
        if initial_val:
            if field.is_a(*fields.MULTIPLE):
                initial_val = split_choices(initial_val)
            elif (field.field_type == fields.CHECKBOX):
                initial_val = (initial_val != 'False')
            self.initial[field_key] = initial_val
        self.fields[field_key] = field_class(**field_args)
        if (field.field_type == fields.DOB):
            _now = datetime.now()
            years = list(range(_now.year, (_now.year - 120), (- 1)))
            self.fields[field_key].widget.years = years
        setattr(self.fields[field_key], 'type', field_class.__name__.lower())
        if (field.required and settings.FORMS_USE_HTML5 and (field.field_type != fields.CHECKBOX_MULTIPLE)):
            self.fields[field_key].widget.attrs['required'] = ''
        if (field.placeholder_text and (not field.default)):
            text = field.placeholder_text
            self.fields[field_key].widget.attrs['placeholder'] = text
Dynamically add each of the form fields for the given form model
instance and its related field model instances.
def __init__(self, form, context, *args, **kwargs):
    '\n        Dynamically add each of the form fields for the given form model\n        instance and its related field model instances.\n        '
    self.form = form
    self.form_fields = form.fields.visible()
    initial = kwargs.pop('initial', {})
    field_entries = {}
    if kwargs.get('instance'):
        for field_entry in kwargs['instance'].fields.all():
            field_entries[field_entry.field_id] = field_entry.value
    super(FormForForm, self).__init__(*args, **kwargs)
    for field in self.form_fields:
        field_key = ('field_%s' % field.id)
        field_class = fields.CLASSES[field.field_type]
        field_widget = fields.WIDGETS.get(field.field_type)
        field_args = {'label': field.label, 'required': field.required, 'help_text': field.help_text}
        if (field.required and (not field.help_text)):
            field_args['help_text'] = _('required')
        arg_names = field_class.__init__.__code__.co_varnames
        if ('max_length' in arg_names):
            field_args['max_length'] = settings.FORMS_FIELD_MAX_LENGTH
        if ('choices' in arg_names):
            choices = list(field.get_choices())
            if ((field.field_type == fields.SELECT) and (field.default not in [c[0] for c in choices])):
                choices.insert(0, (, field.placeholder_text))
            field_args['choices'] = choices
        if (field_widget is not None):
            field_args['widget'] = field_widget
        initial_val = None
        try:
            initial_val = field_entries[field.id]
        except KeyError:
            try:
                initial_val = initial[field_key]
            except KeyError:
                initial_val = Template(field.default).render(context)
        if initial_val:
            if field.is_a(*fields.MULTIPLE):
                initial_val = split_choices(initial_val)
            elif (field.field_type == fields.CHECKBOX):
                initial_val = (initial_val != 'False')
            self.initial[field_key] = initial_val
        self.fields[field_key] = field_class(**field_args)
        if (field.field_type == fields.DOB):
            _now = datetime.now()
            years = list(range(_now.year, (_now.year - 120), (- 1)))
            self.fields[field_key].widget.years = years
        setattr(self.fields[field_key], 'type', field_class.__name__.lower())
        if (field.required and settings.FORMS_USE_HTML5 and (field.field_type != fields.CHECKBOX_MULTIPLE)):
            self.fields[field_key].widget.attrs['required'] = 
        if (field.placeholder_text and (not field.default)):
            text = field.placeholder_text
            self.fields[field_key].widget.attrs['placeholder'] = text