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
This commit is contained in:
Jannis Leidel 2010-11-13 18:42:31 +00:00
parent 3b29fe353b
commit 109f42a981
3 changed files with 11 additions and 2 deletions

View File

@ -12,6 +12,7 @@ from django.forms import ModelForm
from django.forms.models import BaseModelFormSet, modelformset_factory, save_instance from django.forms.models import BaseModelFormSet, modelformset_factory, save_instance
from django.contrib.admin.options import InlineModelAdmin, flatten_fieldsets from django.contrib.admin.options import InlineModelAdmin, flatten_fieldsets
from django.utils.encoding import smart_unicode from django.utils.encoding import smart_unicode
from django.utils.functional import curry
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
@ -407,7 +408,7 @@ class GenericInlineModelAdmin(InlineModelAdmin):
"ct_field": self.ct_field, "ct_field": self.ct_field,
"fk_field": self.ct_fk_field, "fk_field": self.ct_fk_field,
"form": self.form, "form": self.form,
"formfield_callback": self.formfield_for_dbfield, "formfield_callback": curry(self.formfield_for_dbfield, request=request),
"formset": self.formset, "formset": self.formset,
"extra": self.extra, "extra": self.extra,
"can_delete": self.can_delete, "can_delete": self.can_delete,

View File

@ -76,11 +76,15 @@ admin.site.register(EpisodeExclude, inlines=[MediaExcludeInline])
# Generic inline with unique_together # Generic inline with unique_together
# #
class Category(models.Model):
name = models.CharField(max_length=50)
class PhoneNumber(models.Model): class PhoneNumber(models.Model):
content_type = models.ForeignKey(ContentType) content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField() object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id') content_object = generic.GenericForeignKey('content_type', 'object_id')
phone_number = models.CharField(max_length=30) phone_number = models.CharField(max_length=30)
category = models.ForeignKey(Category, null=True, blank=True)
class Meta: class Meta:
unique_together = (('content_type', 'object_id', 'phone_number',),) unique_together = (('content_type', 'object_id', 'phone_number',),)
@ -93,6 +97,7 @@ class PhoneNumberInline(generic.GenericTabularInline):
model = PhoneNumber model = PhoneNumber
admin.site.register(Contact, inlines=[PhoneNumberInline]) admin.site.register(Contact, inlines=[PhoneNumberInline])
admin.site.register(Category)
# #
# Generic inline with can_delete=False # Generic inline with can_delete=False

View File

@ -6,7 +6,7 @@ from django.contrib.contenttypes.generic import generic_inlineformset_factory
# local test models # local test models
from models import Episode, EpisodeExtra, EpisodeMaxNum, EpisodeExclude, \ from models import Episode, EpisodeExtra, EpisodeMaxNum, EpisodeExclude, \
Media, EpisodePermanent, MediaPermanentInline Media, EpisodePermanent, MediaPermanentInline, Category
class GenericAdminViewTest(TestCase): class GenericAdminViewTest(TestCase):
fixtures = ['users.xml'] fixtures = ['users.xml']
@ -190,6 +190,7 @@ class GenericInlineAdminWithUniqueTogetherTest(TestCase):
self.client.logout() self.client.logout()
def testAdd(self): def testAdd(self):
category_id = Category.objects.create(name='male').pk
post_data = { post_data = {
"name": u"John Doe", "name": u"John Doe",
# inline data # 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-MAX_NUM_FORMS": u"0",
"generic_inline_admin-phonenumber-content_type-object_id-0-id": "", "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-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/') 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) response = self.client.post('/generic_inline_admin/admin/generic_inline_admin/contact/add/', post_data)
self.failUnlessEqual(response.status_code, 302) # redirect somewhere self.failUnlessEqual(response.status_code, 302) # redirect somewhere