Ticket #12561: patch-12561.diff

File patch-12561.diff, 2.8 KB (added by Natalia Bidart, 15 years ago)
  • django/contrib/admin/options.py

     
    12271227            "formfield_callback": curry(self.formfield_for_dbfield, request=request),
    12281228            "extra": self.extra,
    12291229            "max_num": self.max_num,
     1230            "can_delete": self.can_delete,
     1231            "can_order": self.can_order,
    12301232        }
    12311233        defaults.update(kwargs)
    12321234        return inlineformset_factory(self.parent_model, self.model, **defaults)
  • tests/regressiontests/admin_inlines/tests.py

     
     1# coding: utf-8
     2
     3from django.test import TestCase
     4from django.contrib import admin
     5
     6# local test models
     7from models import Holder, Inner
     8
     9class TestInline(TestCase):
     10    fixtures = ['admin-views-users.xml']
     11
     12    def setUp(self):
     13        self.holder = Holder(dummy=13)
     14        self.holder.save()
     15        Inner(dummy=42, holder=self.holder).save()
     16
     17        result = self.client.login(username='super', password='secret')
     18        self.failUnlessEqual(result, True)
     19
     20    def tearDown(self):
     21        Inner.objects.all().delete()
     22        Holder.objects.all().delete()
     23        self.client.logout()
     24
     25    def test_can_delete(self):
     26        """
     27        can_delete should be passed to inlineformset factory.
     28        """
     29        url = '/test_admin/admin/admin_inlines/holder/%i/' % self.holder.id
     30        response = self.client.get(url)
     31        with file('test.html', 'w') as f:
     32            f.write(str(response))
     33        self.assertNotContains(response, text='name="neverdeletemodel_set-0-DELETE"')
  • tests/regressiontests/admin_inlines/models.py

     
    33
    44"""
    55from django.db import models
     6from django.contrib import admin
    67from django.contrib.contenttypes.models import ContentType
    78from django.contrib.contenttypes import generic
    89
     
    2930    def __unicode__(self):
    3031        return u'I am %s, a child of %s' % (self.name, self.parent)
    3132
     33
     34class Holder(models.Model):
     35    dummy = models.IntegerField()
     36
     37
     38class Inner(models.Model):
     39    dummy = models.IntegerField()
     40    holder = models.ForeignKey(Holder)
     41
     42
     43class InnerInline(admin.StackedInline):
     44    model = Inner
     45    can_delete = False
     46    can_order = True
     47
     48
     49# Test bug #12561
     50admin.site.register(Holder, inlines=[InnerInline])
     51
    3252__test__ = {'API_TESTS': """
    3353
    3454# Regression test for #9362
Back to Top