Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@jezdez jezdez authored
View
3  django/contrib/contenttypes/generic.py
@@ -12,6 +12,7 @@
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 @@ def get_formset(self, request, obj=None):
"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,
View
5 tests/regressiontests/generic_inline_admin/models.py
@@ -76,11 +76,15 @@ class MediaExcludeInline(generic.GenericTabularInline):
# 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
View
5 tests/regressiontests/generic_inline_admin/tests.py
@@ -6,7 +6,7 @@
# 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 @@ def tearDown(self):
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 @@ def testAdd(self):
"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
Please sign in to comment.
Something went wrong with that request. Please try again.