Ticket #12561: patch-12561-1.diff
File patch-12561-1.diff, 5.2 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/options.py
1182 1182 template = None 1183 1183 verbose_name = None 1184 1184 verbose_name_plural = None 1185 can_delete = False 1186 can_order = False 1185 1187 1186 1188 def __init__(self, parent_model, admin_site): 1187 1189 self.admin_site = admin_site … … 1227 1229 "formfield_callback": curry(self.formfield_for_dbfield, request=request), 1228 1230 "extra": self.extra, 1229 1231 "max_num": self.max_num, 1232 "can_delete": self.can_delete, 1233 "can_order": self.can_order, 1230 1234 } 1231 1235 defaults.update(kwargs) 1232 1236 return inlineformset_factory(self.parent_model, self.model, **defaults) -
tests/regressiontests/modeladmin/models.py
291 291 ... form = AdminConcertForm 292 292 ... model = Concert 293 293 ... fk_name = 'main_band' 294 ... can_delete = True 294 295 295 296 >>> class BandAdmin(ModelAdmin): 296 297 ... inlines = [ -
tests/regressiontests/admin_inlines/tests.py
1 # coding: utf-8 2 3 from django.test import TestCase 4 5 # local test models 6 from models import Holder, Inner, InnerInline 7 8 class TestInline(TestCase): 9 fixtures = ['admin-views-users.xml'] 10 11 def setUp(self): 12 holder = Holder(dummy=13) 13 holder.save() 14 Inner(dummy=42, holder=holder).save() 15 self.change_url = '/test_admin/admin/admin_inlines/holder/%i/' % holder.id 16 17 result = self.client.login(username='super', password='secret') 18 self.failUnlessEqual(result, True) 19 20 def tearDown(self): 21 self.client.logout() 22 23 def test_can_delete(self): 24 """ 25 can_delete should be passed to inlineformset factory. 26 """ 27 response = self.client.get(self.change_url) 28 inner_formset = response.context[-1]['inline_admin_formsets'][0].formset 29 expected = InnerInline.can_delete 30 actual = inner_formset.can_delete 31 self.assertEqual(expected, actual, 'can_delete must be equal') 32 33 def test_can_order(self): 34 """ 35 can_order should be passed to inlineformset factory. 36 """ 37 response = self.client.get(self.change_url) 38 inner_formset = response.context[-1]['inline_admin_formsets'][0].formset 39 expected = InnerInline.can_order 40 actual = inner_formset.can_order 41 self.assertEqual(expected, actual, 'can_order must be equal') -
tests/regressiontests/admin_inlines/fixtures/admin-views-users.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <django-objects version="1.0"> 3 <object pk="100" model="auth.user"> 4 <field type="CharField" name="username">super</field> 5 <field type="CharField" name="first_name">Super</field> 6 <field type="CharField" name="last_name">User</field> 7 <field type="CharField" name="email">super@example.com</field> 8 <field type="CharField" name="password">sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158</field> 9 <field type="BooleanField" name="is_staff">True</field> 10 <field type="BooleanField" name="is_active">True</field> 11 <field type="BooleanField" name="is_superuser">True</field> 12 <field type="DateTimeField" name="last_login">2007-05-30 13:20:10</field> 13 <field type="DateTimeField" name="date_joined">2007-05-30 13:20:10</field> 14 <field to="auth.group" name="groups" rel="ManyToManyRel"></field> 15 <field to="auth.permission" name="user_permissions" rel="ManyToManyRel"></field> 16 </object> 17 </django-objects> -
tests/regressiontests/admin_inlines/models.py
3 3 4 4 """ 5 5 from django.db import models 6 from django.contrib import admin 6 7 from django.contrib.contenttypes.models import ContentType 7 8 from django.contrib.contenttypes import generic 8 9 … … 29 30 def __unicode__(self): 30 31 return u'I am %s, a child of %s' % (self.name, self.parent) 31 32 33 34 class Holder(models.Model): 35 dummy = models.IntegerField() 36 37 38 class Inner(models.Model): 39 dummy = models.IntegerField() 40 holder = models.ForeignKey(Holder) 41 42 43 class InnerInline(admin.StackedInline): 44 model = Inner 45 can_delete = False 46 can_order = True 47 48 49 # Test bug #12561 50 admin.site.register(Holder, inlines=[InnerInline]) 51 32 52 __test__ = {'API_TESTS': """ 33 53 34 54 # Regression test for #9362