diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-05-03 13:39:33 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-05-03 13:39:33 +0000 |
| commit | d7233e7c5adb8a885cb7265f58ef8a3baedbf8e7 (patch) | |
| tree | 2ef170aeb0496f27f0b4c89c168f12c531e2157b /django/contrib/admin | |
| parent | 80a54dd23bfda4bb297f9b13f2a54c1f10664cf5 (diff) | |
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.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10668 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib/admin')
| -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 3243bf86e1..4bef007e6c 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 @@ -146,9 +146,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) @@ -167,6 +167,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 |
