Ticket #9863: 9683.diff

File 9683.diff, 3.0 KB (added by Alex Gaynor, 16 years ago)
  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index 4b697a8..684353e 100644
    a b class BaseInlineFormSet(BaseModelFormSet):  
    545545        if self._pk_field == self.fk:
    546546            form.fields[self._pk_field.name] = InlineForeignKeyField(self.instance, pk_field=True)
    547547        else:
    548             form.fields[self.fk.name] = InlineForeignKeyField(self.instance, label=form.fields[self.fk.name].label)
     548            form.fields[self.fk.name] = InlineForeignKeyField(self.instance,
     549                label=getattr(form.fields.get(self.fk.name), 'label', capfirst(self.fk.verbose_name))
     550            )
    549551
    550552def _get_foreign_key(parent_model, model, fk_name=None):
    551553    """
  • tests/regressiontests/admin_views/models.py

    diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
    index 3546463..b4e64cf 100644
    a b class PodcastAdmin(admin.ModelAdmin):  
    248248
    249249    ordering = ('name',)
    250250
     251class Parent(models.Model):
     252    name = models.CharField(max_length = 128, db_index = True)
     253
     254class Child(models.Model):
     255    parent = models.ForeignKey(Parent, related_name = 'child_set', editable = False)
     256    name = models.CharField(max_length = 30, blank = True)
     257
     258class ChildInline(admin.StackedInline):
     259    model = Child
     260    extra = 10
     261
     262class ParentAdmin(admin.ModelAdmin):
     263    model = Parent
     264    inlines = [
     265       ChildInline,
     266    ]
     267
    251268admin.site.register(Article, ArticleAdmin)
    252269admin.site.register(CustomArticle, CustomArticleAdmin)
    253270admin.site.register(Section, inlines=[ArticleInline])
    admin.site.register(Persona, PersonaAdmin)  
    259276admin.site.register(Subscriber, SubscriberAdmin)
    260277admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)
    261278admin.site.register(Podcast, PodcastAdmin)
     279admin.site.register(Parent, ParentAdmin)
    262280
    263281# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
    264282# That way we cover all four cases:
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 2fd4c07..d42be66 100644
    a b class AdminActionsTest(TestCase):  
    946946        }
    947947        response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
    948948        self.failUnlessEqual(response.status_code, 302)
     949
     950class TestInlineNotEditable(TestCase):
     951    fixtures = ['admin-views-users.xml', ]
     952
     953    def setUp(self):
     954        result = self.client.login(username='super', password='secret')
     955        self.failUnlessEqual(result, True)
     956
     957    def tearDown(self):
     958        self.client.logout()
     959
     960    def test(self):
     961        """
     962        InlineModelAdmin broken?
     963        """
     964        response = self.client.get('/test_admin/admin/admin_views/parent/add/')
     965        self.failUnlessEqual(response.status_code, 200)
Back to Top