Author: brosner
Date: 2009-10-19 14:21:08 -0500 (Mon, 19 Oct 2009)
New Revision: 11633
Modified:
django/branches/releases/1.1.X/django/contrib/admin/validation.py
django/branches/releases/1.1.X/tests/regressiontests/admin_validation/models.py
Log:
[1.1.X] Moved the call to _get_foreign_key to run in all cases catching
incorrect inline setup sooner.
Backport of [11631] from trunk
Modified: django/branches/releases/1.1.X/django/contrib/admin/validation.py
===================================================================
--- django/branches/releases/1.1.X/django/contrib/admin/validation.py
2009-10-19 19:20:52 UTC (rev 11632)
+++ django/branches/releases/1.1.X/django/contrib/admin/validation.py
2009-10-19 19:21:08 UTC (rev 11633)
@@ -149,6 +149,9 @@
validate_inline(inline, cls, model)
def validate_inline(cls, parent, parent_model):
+
+ fk = _get_foreign_key(parent_model, cls.model, fk_name=cls.fk_name,
can_fail=True)
+
# model is already verified to exist and be a Model
if cls.fk_name: # default value is None
f = get_field(cls, cls.model, cls.model._meta, 'fk_name', cls.fk_name)
@@ -169,7 +172,6 @@
# exclude
if hasattr(cls, 'exclude') and cls.exclude:
- 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/branches/releases/1.1.X/tests/regressiontests/admin_validation/models.py
===================================================================
---
django/branches/releases/1.1.X/tests/regressiontests/admin_validation/models.py
2009-10-19 19:20:52 UTC (rev 11632)
+++
django/branches/releases/1.1.X/tests/regressiontests/admin_validation/models.py
2009-10-19 19:21:08 UTC (rev 11633)
@@ -20,7 +20,7 @@
return self.title
-class Model11709(models.Model):
+class TwoAlbumFKAndAnE(models.Model):
album1 = models.ForeignKey(Album, related_name="album1_set")
album2 = models.ForeignKey(Album, related_name="album2_set")
e = models.CharField(max_length=1)
@@ -72,11 +72,27 @@
# 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
+>>> class TwoAlbumFKAndAnEInline(admin.TabularInline):
+... model = TwoAlbumFKAndAnE
... exclude = ("e",)
... fk_name = "album1"
->>> validate_inline(Model11709Inline, None, Album)
+>>> validate_inline(TwoAlbumFKAndAnEInline, None, Album)
+# Ensure inlines validate that they can be used correctly.
+
+>>> class TwoAlbumFKAndAnEInline(admin.TabularInline):
+... model = TwoAlbumFKAndAnE
+
+>>> validate_inline(TwoAlbumFKAndAnEInline, None, Album)
+Traceback (most recent call last):
+ ...
+Exception: <class 'regressiontests.admin_validation.models.TwoAlbumFKAndAnE'>
has more than 1 ForeignKey to <class
'regressiontests.admin_validation.models.Album'>
+
+>>> class TwoAlbumFKAndAnEInline(admin.TabularInline):
+... model = TwoAlbumFKAndAnE
+... fk_name = "album1"
+
+>>> validate_inline(TwoAlbumFKAndAnEInline, 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
-~----------~----~----~----~------~----~------~--~---