Ticket #9932: patch_django_9932.20081230.diff
File patch_django_9932.20081230.diff, 3.0 KB (added by , 16 years ago) |
---|
-
django_src/django/contrib/admin/validation.py
5 5 6 6 from django.core.exceptions import ImproperlyConfigured 7 7 from django.db import models 8 from django.forms.models import BaseModelForm, BaseModelFormSet, fields_for_model 8 from django.forms.models import BaseModelForm, BaseModelFormSet, fields_for_model, _get_foreign_key 9 9 from django.contrib.admin.options import flatten_fieldsets, BaseModelAdmin 10 10 from django.contrib.admin.options import HORIZONTAL, VERTICAL 11 11 … … 117 117 raise ImproperlyConfigured("'%s.inlines[%d].model' does not " 118 118 "inherit from models.Model." % (cls.__name__, idx)) 119 119 validate_base(inline, inline.model) 120 validate_inline(inline )120 validate_inline(inline, cls, model) 121 121 122 def validate_inline(cls ):122 def validate_inline(cls, parent, parent_model): 123 123 # model is already verified to exist and be a Model 124 124 if cls.fk_name: # default value is None 125 125 f = get_field(cls, cls.model, cls.model._meta, 'fk_name', cls.fk_name) … … 138 138 raise ImproperlyConfigured("'%s.formset' does not inherit from " 139 139 "BaseModelFormSet." % cls.__name__) 140 140 141 # exclude 142 if hasattr(cls, 'exclude') and cls.exclude: 143 fk_name = _get_foreign_key(parent_model, cls.model).name 144 if fk_name in cls.exclude: 145 raise ImproperlyConfigured("'%s.exclude' should not contain " 146 "'%s' key because it's used in " 147 "%s." % (cls.__name__, fk_name, parent.__name__)) 148 141 149 def validate_base(cls, model): 142 150 opts = model._meta 143 151 -
django_src/tests/regressiontests/admin_validation/models.py
4 4 5 5 from django.db import models 6 6 7 class Album(models.Model): 8 title = models.CharField(max_length=150) 9 7 10 class Song(models.Model): 8 11 title = models.CharField(max_length=150) 12 first_album = models.ForeignKey(Album) 9 13 10 14 class Meta: 11 15 ordering = ('title',) … … 40 44 ... 41 45 ImproperlyConfigured: 'InvalidFields.fields' refers to field 'spam' that is missing from the form. 42 46 47 # 48 # exclude in InlineModelAdmin should not contain a ForeignKey field used in 49 # ModelAdmin.model 50 # 51 52 >>> class SongInline(admin.StackedInline): 53 ... model = Song 54 ... exclude = ['first_album'] 55 56 >>> class AlbumAdmin(admin.ModelAdmin): 57 ... model = Album 58 ... inlines = [SongInline] 59 60 >>> validate(AlbumAdmin, Album) 61 Traceback (most recent call last): 62 ... 63 ImproperlyConfigured: 'SongInline.exclude' should not contain 'first_album' key because it's used in AlbumAdmin. 64 43 65 """}