Ticket #15907: 15907_at_16452.diff

File 15907_at_16452.diff, 3.2 KB (added by Preston Timmons, 13 years ago)

Patch with fix moved to generic_inlineformset_factory

  • django/contrib/contenttypes/generic.py

    diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
    index 389692d..274a6d6 100644
    a b def generic_inlineformset_factory(model, form=ModelForm,  
    382382        exclude.extend([ct_field.name, fk_field.name])
    383383    else:
    384384        exclude = [ct_field.name, fk_field.name]
     385        if hasattr(form, 'Meta') and hasattr(form.Meta, 'exclude'):
     386            exclude.extend(list(form.Meta.exclude))
     387
    385388    FormSet = modelformset_factory(model, form=form,
    386389                                   formfield_callback=formfield_callback,
    387390                                   formset=formset,
  • 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..205124f 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 modelform and exclude
     78#
     79
     80class Sitcom(Episode):
     81    pass
     82
     83class MediaForm(ModelForm):
     84    class Meta:
     85        model = Media
     86        exclude = ('url',)
     87
     88class MediaInline(generic.GenericTabularInline):
     89    form = MediaForm
     90    model = Media
     91    extra = 1
     92
     93class SitcomAdmin(admin.ModelAdmin):
     94    inlines = (MediaInline, )
     95
     96admin.site.register(Sitcom, SitcomAdmin)
     97
     98
     99#
    76100# Generic inline with unique_together
    77101#
    78102
  • 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 00badc9..081474d 100644
    a b from django.test import TestCase  
    77
    88# local test models
    99from models import (Episode, EpisodeExtra, EpisodeMaxNum, EpisodeExclude,
    10     Media, MediaInline, EpisodePermanent, MediaPermanentInline, Category)
     10    Media, MediaInline, EpisodePermanent, MediaPermanentInline, Category,
     11    Sitcom)
    1112
    1213
    1314class GenericAdminViewTest(TestCase):
    class GenericInlineAdminParametersTest(TestCase):  
    182183        formset = response.context['inline_admin_formsets'][0].formset
    183184        self.assertFalse('url' in formset.forms[0], 'The formset has excluded "url" field.')
    184185
     186    def testModelFormExcludeParam(self):
     187        """
     188        Generic inline formsets should respect exclude on model forms.
     189        """
     190        e = self._create_object(Sitcom)
     191        response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/sitcom/%s/' % e.pk)
     192        formset = response.context['inline_admin_formsets'][0].formset
     193        self.assertFalse('url' in formset.forms[0].fields, 'The formset has excluded "url" field.')
     194
    185195class GenericInlineAdminWithUniqueTogetherTest(TestCase):
    186196    fixtures = ['users.xml']
    187197
Back to Top