Ticket #14670: issue14670.1.diff

File issue14670.1.diff, 3.9 KB (added by Gregor Müllegger, 14 years ago)

Adding test suite and fix for the issue.

  • django/contrib/contenttypes/generic.py

    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  
    1212from django.forms.models import BaseModelFormSet, modelformset_factory, save_instance
    1313from django.contrib.admin.options import InlineModelAdmin, flatten_fieldsets
    1414from django.utils.encoding import smart_unicode
     15from django.utils.functional import curry
    1516
    1617from django.contrib.contenttypes.models import ContentType
    1718
    class GenericInlineModelAdmin(InlineModelAdmin):  
    407408            "ct_field": self.ct_field,
    408409            "fk_field": self.ct_fk_field,
    409410            "form": self.form,
    410             "formfield_callback": self.formfield_for_dbfield,
     411            "formfield_callback": curry(self.formfield_for_dbfield, request=request),
    411412            "formset": self.formset,
    412413            "extra": self.extra,
    413414            "can_delete": self.can_delete,
  • tests/regressiontests/generic_inline_admin/models.py

    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])  
    7676# Generic inline with unique_together
    7777#
    7878
     79class Category(models.Model):
     80    name = models.CharField(max_length=50)
     81
    7982class PhoneNumber(models.Model):
    8083    content_type = models.ForeignKey(ContentType)
    8184    object_id = models.PositiveIntegerField()
    8285    content_object = generic.GenericForeignKey('content_type', 'object_id')
    8386    phone_number = models.CharField(max_length=30)
     87    category = models.ForeignKey(Category, null=True, blank=True)
    8488
    8589    class Meta:
    8690        unique_together = (('content_type', 'object_id', 'phone_number',),)
    class PhoneNumberInline(generic.GenericTabularInline):  
    9397    model = PhoneNumber
    9498
    9599admin.site.register(Contact, inlines=[PhoneNumberInline])
     100admin.site.register(Category)
    96101
    97102#
    98103# Generic inline with can_delete=False
  • tests/regressiontests/generic_inline_admin/tests.py

    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  
    66
    77# local test models
    88from models import Episode, EpisodeExtra, EpisodeMaxNum, EpisodeExclude, \
    9                    Media, EpisodePermanent, MediaPermanentInline
     9                   Media, EpisodePermanent, MediaPermanentInline, Category
    1010
    1111class GenericAdminViewTest(TestCase):
    1212    fixtures = ['users.xml']
    class GenericInlineAdminWithUniqueTogetherTest(TestCase):  
    190190        self.client.logout()
    191191
    192192    def testAdd(self):
     193        category_id = Category.objects.create(name='male').pk
    193194        post_data = {
    194195            "name": u"John Doe",
    195196            # inline data
    class GenericInlineAdminWithUniqueTogetherTest(TestCase):  
    198199            "generic_inline_admin-phonenumber-content_type-object_id-MAX_NUM_FORMS": u"0",
    199200            "generic_inline_admin-phonenumber-content_type-object_id-0-id": "",
    200201            "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,
    201203        }
    202204        response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/contact/add/')
     205        self.failUnlessEqual(response.status_code, 200)
    203206        response = self.client.post('/generic_inline_admin/admin/generic_inline_admin/contact/add/', post_data)
    204207        self.failUnlessEqual(response.status_code, 302) # redirect somewhere
    205208
Back to Top