Ticket #5358: 5358_fk_name_fix.diff

File 5358_fk_name_fix.diff, 937 bytes (added by Brian Rosner, 17 years ago)

my solution to this.

  • django/newforms/models.py

     
    319319        fks_to_parent = [f for f in opts.fields if isinstance(f, ForeignKey) and f.rel.to == parent_model]
    320320        if len(fks_to_parent) == 1:
    321321            fk = fks_to_parent[0]
     322            fk_name = fk.name
    322323        elif len(fks_to_parent) == 0:
    323324            raise Exception("%s has no ForeignKey to %s" % (model, parent_model))
    324325        else:
    325326            raise Exception("%s has more than 1 ForeignKey to %s" % (model, parent_model))
     327    else:
     328        fk = [f for f in opts.fields if f.name == fk_name][0]
    326329    # let the formset handle object deletion by default
    327330    FormSet = formset_for_model(model, formset=InlineFormset, fields=fields,
    328331                                formfield_callback=formfield_callback,
Back to Top