summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2008-08-01 00:27:40 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2008-08-01 00:27:40 +0000
commit83f0d54d41a23ae856376942e1ece8fd8d6efa34 (patch)
tree0d28c3363c3111f2bf33920a214a171d1fe96224 /django
parentb0d1612c9e44523752277b33cf24c8bc7ca8c374 (diff)
Modified inline handling to allow for an inline formset to be displayed when the foreign key exists on a parent class.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8165 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/forms/models.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index 56e19e7145..4f1f86d801 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -441,13 +441,20 @@ def _get_foreign_key(parent_model, model, fk_name=None):
fks_to_parent = [f for f in opts.fields if f.name == fk_name]
if len(fks_to_parent) == 1:
fk = fks_to_parent[0]
- if not isinstance(fk, ForeignKey) or fk.rel.to != parent_model:
+ if not isinstance(fk, ForeignKey) or \
+ (fk.rel.to != parent_model and
+ fk.rel.to not in parent_model._meta.parents.keys()):
raise Exception("fk_name '%s' is not a ForeignKey to %s" % (fk_name, parent_model))
elif len(fks_to_parent) == 0:
raise Exception("%s has no field named '%s'" % (model, fk_name))
else:
# Try to discover what the ForeignKey from model to parent_model is
- fks_to_parent = [f for f in opts.fields if isinstance(f, ForeignKey) and f.rel.to == parent_model]
+ fks_to_parent = [
+ f for f in opts.fields
+ if isinstance(f, ForeignKey)
+ and (f.rel.to == parent_model
+ or f.rel.to in parent_model._meta.parents.keys())
+ ]
if len(fks_to_parent) == 1:
fk = fks_to_parent[0]
elif len(fks_to_parent) == 0: