1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

[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
This commit is contained in:
Russell Keith-Magee
2009-05-03 13:48:27 +00:00
parent f137a7391e
commit 0e5c80f86c
2 changed files with 33 additions and 7 deletions

View File

@@ -4,12 +4,16 @@ Tests of ModelAdmin validation logic.
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)
class Meta:
ordering = ('title',)
def __unicode__(self):
return self.title
@@ -19,9 +23,7 @@ __test__ = {'API_TESTS':"""
>>> from django.contrib import admin
>>> from django.contrib.admin.validation import validate
#
# Regression test for #8027: custom ModelForms with fields/fieldsets
#
>>> class SongForm(forms.ModelForm):
... pass
@@ -40,4 +42,20 @@ Traceback (most recent call last):
...
ImproperlyConfigured: 'InvalidFields.fields' refers to field 'spam' that is missing from the form.
# Regression test for #9932 - exclude in InlineModelAdmin
# should not contain the ForeignKey field used in ModelAdmin.model
>>> class SongInline(admin.StackedInline):
... model = Song
... exclude = ['album']
>>> class AlbumAdmin(admin.ModelAdmin):
... model = Album
... inlines = [SongInline]
>>> validate(AlbumAdmin, Album)
Traceback (most recent call last):
...
ImproperlyConfigured: SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album.
"""}