Author: brosner
Date: 2009-10-19 14:17:07 -0500 (Mon, 19 Oct 2009)
New Revision: 11630

Modified:
   django/trunk/django/contrib/admin/validation.py
   django/trunk/tests/regressiontests/admin_validation/models.py
Log:
Fixed #11709 ?\226?\128?\148 Pass inline fk_name attribute when grabbing 
foreign key to test for exclusion. Thanks yishaibeeri for the report.

Modified: django/trunk/django/contrib/admin/validation.py
===================================================================
--- django/trunk/django/contrib/admin/validation.py     2009-10-17 17:46:44 UTC 
(rev 11629)
+++ django/trunk/django/contrib/admin/validation.py     2009-10-19 19:17:07 UTC 
(rev 11630)
@@ -169,7 +169,7 @@
 
     # exclude
     if hasattr(cls, 'exclude') and cls.exclude:
-        fk = _get_foreign_key(parent_model, cls.model, can_fail=True)
+        fk = _get_foreign_key(parent_model, cls.model, fk_name=cls.fk_name, 
can_fail=True)
         if fk and fk.name in cls.exclude:
             raise ImproperlyConfigured("%s cannot exclude the field "
                     "'%s' - this is the foreign key to the parent model "

Modified: django/trunk/tests/regressiontests/admin_validation/models.py
===================================================================
--- django/trunk/tests/regressiontests/admin_validation/models.py       
2009-10-17 17:46:44 UTC (rev 11629)
+++ django/trunk/tests/regressiontests/admin_validation/models.py       
2009-10-19 19:17:07 UTC (rev 11630)
@@ -4,9 +4,11 @@
 
 from django.db import models
 
+
 class Album(models.Model):
     title = models.CharField(max_length=150)
 
+
 class Song(models.Model):
     title = models.CharField(max_length=150)
     album = models.ForeignKey(Album)
@@ -17,11 +19,19 @@
     def __unicode__(self):
         return self.title
 
+
+class Model11709(models.Model):
+    album1 = models.ForeignKey(Album, related_name="album1_set")
+    album2 = models.ForeignKey(Album, related_name="album2_set")
+    e = models.CharField(max_length=1)
+
+
+
 __test__ = {'API_TESTS':"""
 
 >>> from django import forms
 >>> from django.contrib import admin
->>> from django.contrib.admin.validation import validate
+>>> from django.contrib.admin.validation import validate, validate_inline
 
 # Regression test for #8027: custom ModelForms with fields/fieldsets
 
@@ -58,4 +68,15 @@
     ...
 ImproperlyConfigured: SongInline cannot exclude the field 'album' - this is 
the foreign key to the parent model Album.
 
+# Regression test for #11709 - when testing for fk excluding (when exclude is
+# given) make sure fk_name is honored or things blow up when there is more
+# than one fk to the parent model.
+
+>>> class Model11709Inline(admin.TabularInline):
+...     model = Model11709
+...     exclude = ("e",)
+...     fk_name = "album1"
+
+>>> validate_inline(Model11709Inline, None, Album)
+
 """}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to