Ticket #20942: 20942-no-tests.diff

File 20942-no-tests.diff, 1.2 KB (added by Craig de Stigter, 11 years ago)
  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index a5b82e5..fe37c60 100644
    a b def _get_foreign_key(parent_model, model, fk_name=None, can_fail=False):  
    913913        if len(fks_to_parent) == 1:
    914914            fk = fks_to_parent[0]
    915915            if not isinstance(fk, ForeignKey) or \
    916                     (fk.rel.to != parent_model and
    917                      fk.rel.to not in parent_model._meta.get_parent_list()):
     916                    not issubclass(parent_model, fk.rel.to):
    918917                raise Exception("fk_name '%s' is not a ForeignKey to %s" % (fk_name, parent_model))
    919918        elif len(fks_to_parent) == 0:
    920919            raise Exception("%s has no field named '%s'" % (model, fk_name))
    921920    else:
    922921        # Try to discover what the ForeignKey from model to parent_model is
     922
    923923        fks_to_parent = [
    924924            f for f in opts.fields
    925925            if isinstance(f, ForeignKey)
    926             and (f.rel.to == parent_model
    927                 or f.rel.to in parent_model._meta.get_parent_list())
     926            and issubclass(parent_model, f.rel.to)
    928927        ]
    929928        if len(fks_to_parent) == 1:
    930929            fk = fks_to_parent[0]
Back to Top