Ticket #15907: 15907_test_case_at_r16105.diff

File 15907_test_case_at_r16105.diff, 2.7 KB (added by Preston Timmons, 14 years ago)

Test case to demonstrate bug

  • tests/regressiontests/generic_inline_admin/models.py

    diff --git a/tests/regressiontests/generic_inline_admin/models.py b/tests/regressiontests/generic_inline_admin/models.py
    index fb6363e..ed412bf 100644
    a b from django.db import models  
    22from django.contrib import admin
    33from django.contrib.contenttypes import generic
    44from django.contrib.contenttypes.models import ContentType
     5from django.forms.models import ModelForm
    56
    67class Episode(models.Model):
    78    name = models.CharField(max_length=100)
    class MediaExcludeInline(generic.GenericTabularInline):  
    7374admin.site.register(EpisodeExclude, inlines=[MediaExcludeInline])
    7475
    7576#
     77# Generic inline with custom modelform and exclude
     78#
     79
     80class EpisodeModelFormExclude(Episode):
     81    pass
     82
     83class ModelFormWithExclude(ModelForm):
     84    class Meta:
     85        model = Media
     86        exclude = ('url',)
     87
     88class MediaWithModelFormExcludeInline(generic.GenericTabularInline):
     89    form = ModelFormWithExclude
     90    model = Media
     91    extra = 1
     92
     93class EpisodeModelFormExcludeAdmin(admin.ModelAdmin):
     94    inlines = (MediaWithModelFormExcludeInline, )
     95
     96admin.site.register(EpisodeModelFormExclude, EpisodeModelFormExcludeAdmin)
     97
     98#
    7699# Generic inline with unique_together
    77100#
    78101
  • tests/regressiontests/generic_inline_admin/tests.py

    diff --git a/tests/regressiontests/generic_inline_admin/tests.py b/tests/regressiontests/generic_inline_admin/tests.py
    index c40b6dd..4a151bd 100644
    a b from django.test import TestCase  
    66
    77# local test models
    88from models import Episode, EpisodeExtra, EpisodeMaxNum, EpisodeExclude, \
    9                    Media, EpisodePermanent, MediaPermanentInline, Category
     9                   EpisodeModelFormExclude, Media, EpisodePermanent, \
     10                   MediaPermanentInline, Category
    1011
    1112
    1213class GenericAdminViewTest(TestCase):
    class GenericInlineAdminParametersTest(TestCase):  
    181182        formset = response.context['inline_admin_formsets'][0].formset
    182183        self.assertFalse('url' in formset.forms[0], 'The formset has excluded "url" field.')
    183184
     185    def testModelFormExcludeParam(self):
     186        """
     187        Generic inline formsets should respect exclude on custom model forms.
     188        """
     189        e = self._create_object(EpisodeModelFormExclude)
     190        response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episodemodelformexclude/%s/' % e.pk)
     191        formset = response.context['inline_admin_formsets'][0].formset
     192        self.assertFalse('url' in formset.forms[0].fields, 'The formset has excluded "url" field.')
     193
    184194class GenericInlineAdminWithUniqueTogetherTest(TestCase):
    185195    fixtures = ['users.xml']
    186196
Back to Top