From 109f42a981cf28c2da8a82f59536a3a732572f02 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sat, 13 Nov 2010 18:42:31 +0000 Subject: [PATCH] Fixed #14670 -- Made GenericTabularInline aware of changes made in r13708. Thanks, gregmuellegger. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14555 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/contenttypes/generic.py | 3 ++- tests/regressiontests/generic_inline_admin/models.py | 5 +++++ tests/regressiontests/generic_inline_admin/tests.py | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py index 3243458f50..fd05a301b9 100644 --- a/django/contrib/contenttypes/generic.py +++ b/django/contrib/contenttypes/generic.py @@ -12,6 +12,7 @@ from django.forms import ModelForm from django.forms.models import BaseModelFormSet, modelformset_factory, save_instance from django.contrib.admin.options import InlineModelAdmin, flatten_fieldsets from django.utils.encoding import smart_unicode +from django.utils.functional import curry from django.contrib.contenttypes.models import ContentType @@ -407,7 +408,7 @@ class GenericInlineModelAdmin(InlineModelAdmin): "ct_field": self.ct_field, "fk_field": self.ct_fk_field, "form": self.form, - "formfield_callback": self.formfield_for_dbfield, + "formfield_callback": curry(self.formfield_for_dbfield, request=request), "formset": self.formset, "extra": self.extra, "can_delete": self.can_delete, diff --git a/tests/regressiontests/generic_inline_admin/models.py b/tests/regressiontests/generic_inline_admin/models.py index 329c4877eb..fb6363e2bb 100644 --- a/tests/regressiontests/generic_inline_admin/models.py +++ b/tests/regressiontests/generic_inline_admin/models.py @@ -76,11 +76,15 @@ admin.site.register(EpisodeExclude, inlines=[MediaExcludeInline]) # Generic inline with unique_together # +class Category(models.Model): + name = models.CharField(max_length=50) + class PhoneNumber(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') phone_number = models.CharField(max_length=30) + category = models.ForeignKey(Category, null=True, blank=True) class Meta: unique_together = (('content_type', 'object_id', 'phone_number',),) @@ -93,6 +97,7 @@ class PhoneNumberInline(generic.GenericTabularInline): model = PhoneNumber admin.site.register(Contact, inlines=[PhoneNumberInline]) +admin.site.register(Category) # # Generic inline with can_delete=False diff --git a/tests/regressiontests/generic_inline_admin/tests.py b/tests/regressiontests/generic_inline_admin/tests.py index 0626699292..f0e8f3e558 100644 --- a/tests/regressiontests/generic_inline_admin/tests.py +++ b/tests/regressiontests/generic_inline_admin/tests.py @@ -6,7 +6,7 @@ from django.contrib.contenttypes.generic import generic_inlineformset_factory # local test models from models import Episode, EpisodeExtra, EpisodeMaxNum, EpisodeExclude, \ - Media, EpisodePermanent, MediaPermanentInline + Media, EpisodePermanent, MediaPermanentInline, Category class GenericAdminViewTest(TestCase): fixtures = ['users.xml'] @@ -190,6 +190,7 @@ class GenericInlineAdminWithUniqueTogetherTest(TestCase): self.client.logout() def testAdd(self): + category_id = Category.objects.create(name='male').pk post_data = { "name": u"John Doe", # inline data @@ -198,8 +199,10 @@ class GenericInlineAdminWithUniqueTogetherTest(TestCase): "generic_inline_admin-phonenumber-content_type-object_id-MAX_NUM_FORMS": u"0", "generic_inline_admin-phonenumber-content_type-object_id-0-id": "", "generic_inline_admin-phonenumber-content_type-object_id-0-phone_number": "555-555-5555", + "generic_inline_admin-phonenumber-content_type-object_id-0-category": "%s" % category_id, } response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/contact/add/') + self.failUnlessEqual(response.status_code, 200) response = self.client.post('/generic_inline_admin/admin/generic_inline_admin/contact/add/', post_data) self.failUnlessEqual(response.status_code, 302) # redirect somewhere