diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-05-03 13:48:27 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-05-03 13:48:27 +0000 |
| commit | 0e5c80f86c8d221e57b21d658e81de554cda658f (patch) | |
| tree | c88f2f76657db8cd0e784bb8ee97102cb172c4dd /django | |
| parent | f137a7391e56f35231cf66df29bff8097b5cc98d (diff) | |
[1.0.X] Fixed #9932 -- Added a validation error when an inline tries to exclude the foreign key that provides the link to the parent model. Thanks to david for the report and patch.
Merge of r10668 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10672 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/admin/validation.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index ccade8a3ef..d9927d59a7 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -5,7 +5,7 @@ except NameError: from django.core.exceptions import ImproperlyConfigured from django.db import models -from django.forms.models import BaseModelForm, BaseModelFormSet, fields_for_model +from django.forms.models import BaseModelForm, BaseModelFormSet, fields_for_model, _get_foreign_key from django.contrib.admin.options import flatten_fieldsets, BaseModelAdmin from django.contrib.admin.options import HORIZONTAL, VERTICAL @@ -117,9 +117,9 @@ def validate(cls, model): raise ImproperlyConfigured("'%s.inlines[%d].model' does not " "inherit from models.Model." % (cls.__name__, idx)) validate_base(inline, inline.model) - validate_inline(inline) + validate_inline(inline, cls, model) -def validate_inline(cls): +def validate_inline(cls, parent, parent_model): # 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) @@ -138,6 +138,14 @@ def validate_inline(cls): raise ImproperlyConfigured("'%s.formset' does not inherit from " "BaseModelFormSet." % cls.__name__) + # exclude + if hasattr(cls, 'exclude') and cls.exclude: + fk_name = _get_foreign_key(parent_model, cls.model).name + if fk_name in cls.exclude: + raise ImproperlyConfigured("%s cannot exclude the field " + "'%s' - this is the foreign key to the parent model " + "%s." % (cls.__name__, fk_name, parent_model.__name__)) + def validate_base(cls, model): opts = model._meta |
