diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
index 3243458..fd05a30 100644
a
|
b
|
from django.forms import ModelForm
|
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 | |
… |
… |
class GenericInlineModelAdmin(InlineModelAdmin):
|
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, |
diff --git a/tests/regressiontests/generic_inline_admin/models.py b/tests/regressiontests/generic_inline_admin/models.py
index 329c487..fb6363e 100644
a
|
b
|
admin.site.register(EpisodeExclude, inlines=[MediaExcludeInline])
|
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',),) |
… |
… |
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 |
diff --git a/tests/regressiontests/generic_inline_admin/tests.py b/tests/regressiontests/generic_inline_admin/tests.py
index 0626699..f0e8f3e 100644
a
|
b
|
from django.contrib.contenttypes.generic import generic_inlineformset_factory
|
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'] |
… |
… |
class GenericInlineAdminWithUniqueTogetherTest(TestCase):
|
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 |
… |
… |
class GenericInlineAdminWithUniqueTogetherTest(TestCase):
|
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 | |