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):
|
913 | 913 | if len(fks_to_parent) == 1: |
914 | 914 | fk = fks_to_parent[0] |
915 | 915 | 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): |
918 | 917 | raise Exception("fk_name '%s' is not a ForeignKey to %s" % (fk_name, parent_model)) |
919 | 918 | elif len(fks_to_parent) == 0: |
920 | 919 | raise Exception("%s has no field named '%s'" % (model, fk_name)) |
921 | 920 | else: |
922 | 921 | # Try to discover what the ForeignKey from model to parent_model is |
| 922 | |
923 | 923 | fks_to_parent = [ |
924 | 924 | f for f in opts.fields |
925 | 925 | 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) |
928 | 927 | ] |
929 | 928 | if len(fks_to_parent) == 1: |
930 | 929 | fk = fks_to_parent[0] |