Ticket #14283: fix14283.patch

File fix14283.patch, 3.1 KB (added by Matthias Kestenholz, 14 years ago)
  • django/contrib/contenttypes/generic.py

    diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
    index 40c3336..a8f5de9 100644
    a b from django.forms import ModelForm  
    1212from django.forms.models import BaseModelFormSet, modelformset_factory, save_instance
    1313from django.contrib.admin.options import InlineModelAdmin, flatten_fieldsets
    1414from django.utils.encoding import smart_unicode
     15from django.utils.functional import curry
    1516
    1617class GenericForeignKey(object):
    1718    """
    class GenericInlineModelAdmin(InlineModelAdmin):  
    391392            "ct_field": self.ct_field,
    392393            "fk_field": self.ct_fk_field,
    393394            "form": self.form,
    394             "formfield_callback": self.formfield_for_dbfield,
     395            "formfield_callback": curry(self.formfield_for_dbfield, request=request),
    395396            "formset": self.formset,
    396397            "extra": self.extra,
    397398            "can_delete": self.can_delete,
  • 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 329c487..144d4ab 100644
    a b class MediaPermanentInline(generic.GenericTabularInline):  
    106106    can_delete = False
    107107
    108108admin.site.register(EpisodePermanent, inlines=[MediaPermanentInline])
     109
     110
     111#
     112# Generic inline with additional model
     113#
     114
     115class ModelC(models.Model):
     116    relation_b = models.ForeignKey('ModelB')
     117
     118    tagged_object = generic.GenericForeignKey()
     119    content_type = models.ForeignKey(ContentType)
     120    object_id = models.PositiveIntegerField()
     121
     122class ModelA(models.Model):
     123    pass
     124
     125class ModelB(models.Model):
     126    pass
     127
     128
     129class ModelCInline(generic.GenericTabularInline):
     130    model = ModelC
     131
     132
     133class ModelAAdmin(admin.ModelAdmin):
     134    inlines = [ModelCInline]
     135
     136admin.site.register(ModelA, ModelAAdmin)
     137admin.site.register(ModelB)
  • 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 0626699..6b32761 100644
    a b class GenericInlineAdminWithUniqueTogetherTest(TestCase):  
    203203        response = self.client.post('/generic_inline_admin/admin/generic_inline_admin/contact/add/', post_data)
    204204        self.failUnlessEqual(response.status_code, 302) # redirect somewhere
    205205
     206class GenericInlineAdminWithForeignKeyTest(TestCase):
     207    fixtures = ['users.xml']
     208
     209    def setUp(self):
     210        self.client.login(username='super', password='secret')
     211
     212    def tearDown(self):
     213        self.client.logout()
     214
     215    def testBasicAddGet(self):
     216        """
     217        Regression test for #14283
     218        """
     219
     220        response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/modela/add/')
     221        self.failUnlessEqual(response.status_code, 200)
     222
    206223class NoInlineDeletionTest(TestCase):
    207224    def test_no_deletion(self):
    208225        fake_site = object()
Back to Top