Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14670 -- Made GenericTabularInline aware of changes made in r1…

…3708. Thanks, gregmuellegger.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14555 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 109f42a981cf28c2da8a82f59536a3a732572f02 1 parent 3b29fe3
Jannis Leidel authored November 13, 2010
3  django/contrib/contenttypes/generic.py
@@ -12,6 +12,7 @@
12 12
 from django.forms.models import BaseModelFormSet, modelformset_factory, save_instance
13 13
 from django.contrib.admin.options import InlineModelAdmin, flatten_fieldsets
14 14
 from django.utils.encoding import smart_unicode
  15
+from django.utils.functional import curry
15 16
 
16 17
 from django.contrib.contenttypes.models import ContentType
17 18
 
@@ -407,7 +408,7 @@ def get_formset(self, request, obj=None):
407 408
             "ct_field": self.ct_field,
408 409
             "fk_field": self.ct_fk_field,
409 410
             "form": self.form,
410  
-            "formfield_callback": self.formfield_for_dbfield,
  411
+            "formfield_callback": curry(self.formfield_for_dbfield, request=request),
411 412
             "formset": self.formset,
412 413
             "extra": self.extra,
413 414
             "can_delete": self.can_delete,
5  tests/regressiontests/generic_inline_admin/models.py
@@ -76,11 +76,15 @@ class MediaExcludeInline(generic.GenericTabularInline):
76 76
 # Generic inline with unique_together
77 77
 #
78 78
 
  79
+class Category(models.Model):
  80
+    name = models.CharField(max_length=50)
  81
+
79 82
 class PhoneNumber(models.Model):
80 83
     content_type = models.ForeignKey(ContentType)
81 84
     object_id = models.PositiveIntegerField()
82 85
     content_object = generic.GenericForeignKey('content_type', 'object_id')
83 86
     phone_number = models.CharField(max_length=30)
  87
+    category = models.ForeignKey(Category, null=True, blank=True)
84 88
 
85 89
     class Meta:
86 90
         unique_together = (('content_type', 'object_id', 'phone_number',),)
@@ -93,6 +97,7 @@ class PhoneNumberInline(generic.GenericTabularInline):
93 97
     model = PhoneNumber
94 98
 
95 99
 admin.site.register(Contact, inlines=[PhoneNumberInline])
  100
+admin.site.register(Category)
96 101
 
97 102
 #
98 103
 # Generic inline with can_delete=False
5  tests/regressiontests/generic_inline_admin/tests.py
@@ -6,7 +6,7 @@
6 6
 
7 7
 # local test models
8 8
 from models import Episode, EpisodeExtra, EpisodeMaxNum, EpisodeExclude, \
9  
-                   Media, EpisodePermanent, MediaPermanentInline
  9
+                   Media, EpisodePermanent, MediaPermanentInline, Category
10 10
 
11 11
 class GenericAdminViewTest(TestCase):
12 12
     fixtures = ['users.xml']
@@ -190,6 +190,7 @@ def tearDown(self):
190 190
         self.client.logout()
191 191
 
192 192
     def testAdd(self):
  193
+        category_id = Category.objects.create(name='male').pk
193 194
         post_data = {
194 195
             "name": u"John Doe",
195 196
             # inline data
@@ -198,8 +199,10 @@ def testAdd(self):
198 199
             "generic_inline_admin-phonenumber-content_type-object_id-MAX_NUM_FORMS": u"0",
199 200
             "generic_inline_admin-phonenumber-content_type-object_id-0-id": "",
200 201
             "generic_inline_admin-phonenumber-content_type-object_id-0-phone_number": "555-555-5555",
  202
+            "generic_inline_admin-phonenumber-content_type-object_id-0-category": "%s" % category_id,
201 203
         }
202 204
         response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/contact/add/')
  205
+        self.failUnlessEqual(response.status_code, 200)
203 206
         response = self.client.post('/generic_inline_admin/admin/generic_inline_admin/contact/add/', post_data)
204 207
         self.failUnlessEqual(response.status_code, 302) # redirect somewhere
205 208
 

0 notes on commit 109f42a

Please sign in to comment.
Something went wrong with that request. Please try again.