def _unwind(self):
        if hasattr(self, '_forms'):
            return
        related_form = self.related_form
        if related_form is None:
            raise FormError('Related form not specified')
        prefix = ''
        if related_form.prefix:
            prefix = '%s_' % related_form.prefix
        prefix = '%s%s_' % (prefix, self.name)
        self.prefix = prefix
        errors = self._errors = {}
        forms = self._forms = []
        is_bound = self.is_bound
        nf = '%s%s' % (self.prefix, self.NUMBER_OF_FORMS_CODE)
        instances = []

        try:

            if is_bound:
                if nf not in related_form.rawdata:
                    raise ValidationError(
                        'Could not find number of "%s" forms' % self.name)
                num_forms = int(related_form.rawdata[nf])
            else:
                related = related_form.instance
                num_forms = 0
                if related is not None and related.id:
                    if self.instances_from_related:
                        instances = self.instances_from_related(related)
                    else:
                        instances = self.mapper.filter(
                            **{self.related_name: related})
                    instances = list(instances)
                    num_forms = self.extra_length + len(instances)
                num_forms = max(num_forms, self.initial_length)
            self.num_forms = HiddenInput(name=nf, value=num_forms)

            for idx, instance in zip_longest(range(num_forms), instances):
                f = self.get_form(self.prefix, idx, instance)
                if f is not None:
                    forms.append(f)
                    errors.update(f.errors)

        except __HOLE__ as err:
            self.related_form.add_error_message(err)
            errors['form'] = err

        else:
            if is_bound and not errors and self.clean:
                try:
                    self.clean(self)
                except ValidationError as err:
                    self.form.add_error(err)
dataset/ETHPy150Open quantmind/lux/lux/forms/formsets.py/FormSet._unwind