Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #11709 — Pass inline fk_name attribute when grabbing fo…

…reign key to test for exclusion. Thanks yishaibeeri for the report.

Backport of [11630] from trunk

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11632 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fb8653ad0e4f4a927c82ea8009dbd3877412e4db 1 parent 72bc081
Brian Rosner authored
2  django/contrib/admin/validation.py
@@ -169,7 +169,7 @@ def validate_inline(cls, parent, parent_model):
169 169
 
170 170
     # exclude
171 171
     if hasattr(cls, 'exclude') and cls.exclude:
172  
-        fk = _get_foreign_key(parent_model, cls.model, can_fail=True)
  172
+        fk = _get_foreign_key(parent_model, cls.model, fk_name=cls.fk_name, can_fail=True)
173 173
         if fk and fk.name in cls.exclude:
174 174
             raise ImproperlyConfigured("%s cannot exclude the field "
175 175
                     "'%s' - this is the foreign key to the parent model "
23  tests/regressiontests/admin_validation/models.py
@@ -4,9 +4,11 @@
4 4
 
5 5
 from django.db import models
6 6
 
  7
+
7 8
 class Album(models.Model):
8 9
     title = models.CharField(max_length=150)
9 10
 
  11
+
10 12
 class Song(models.Model):
11 13
     title = models.CharField(max_length=150)
12 14
     album = models.ForeignKey(Album)
@@ -17,11 +19,19 @@ class Meta:
17 19
     def __unicode__(self):
18 20
         return self.title
19 21
 
  22
+
  23
+class Model11709(models.Model):
  24
+    album1 = models.ForeignKey(Album, related_name="album1_set")
  25
+    album2 = models.ForeignKey(Album, related_name="album2_set")
  26
+    e = models.CharField(max_length=1)
  27
+
  28
+
  29
+
20 30
 __test__ = {'API_TESTS':"""
21 31
 
22 32
 >>> from django import forms
23 33
 >>> from django.contrib import admin
24  
->>> from django.contrib.admin.validation import validate
  34
+>>> from django.contrib.admin.validation import validate, validate_inline
25 35
 
26 36
 # Regression test for #8027: custom ModelForms with fields/fieldsets
27 37
 
@@ -58,4 +68,15 @@ def __unicode__(self):
58 68
     ...
59 69
 ImproperlyConfigured: SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album.
60 70
 
  71
+# Regression test for #11709 - when testing for fk excluding (when exclude is
  72
+# given) make sure fk_name is honored or things blow up when there is more
  73
+# than one fk to the parent model.
  74
+
  75
+>>> class Model11709Inline(admin.TabularInline):
  76
+...     model = Model11709
  77
+...     exclude = ("e",)
  78
+...     fk_name = "album1"
  79
+
  80
+>>> validate_inline(Model11709Inline, None, Album)
  81
+
61 82
 """}

0 notes on commit fb8653a

Please sign in to comment.
Something went wrong with that request. Please try again.