Ticket #6191: multiple-fk-delete-view.diff
File multiple-fk-delete-view.diff, 4.1 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/util.py
85 85 nh = _nest_help # Bind to local variable for performance 86 86 if current_depth > 16: 87 87 return # Avoid recursing too deep. 88 opts_seen = []89 88 for related in opts.get_all_related_objects(): 90 89 has_admin = related.model in admin_site._registry 91 if related.opts in opts_seen:92 continue93 opts_seen.append(related.opts)94 90 rel_opts_name = related.get_accessor_name() 95 91 if isinstance(related.field.rel, models.OneToOneRel): 96 92 try: … … 148 144 perms_needed.add(related.opts.verbose_name) 149 145 for related in opts.get_all_related_many_to_many_objects(): 150 146 has_admin = related.model in admin_site._registry 151 if related.opts in opts_seen:152 continue153 opts_seen.append(related.opts)154 147 rel_opts_name = related.get_accessor_name() 155 148 has_related_objs = False 156 149 -
tests/regressiontests/admin_views/tests.py
18 18 ExternalSubscriber, FooAccount, Gallery, ModelWithStringPrimaryKey, \ 19 19 Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \ 20 20 Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \ 21 Category 21 Category, Color, MulticoloredThing 22 22 23 23 try: 24 24 set … … 323 323 324 324 delete_user.user_permissions.add(get_perm(Section, 325 325 Section._meta.get_delete_permission())) 326 delete_user.user_permissions.add(get_perm(Color, 327 Color._meta.get_delete_permission())) 328 delete_user.user_permissions.add(get_perm(MulticoloredThing, 329 MulticoloredThing._meta.get_delete_permission())) 326 330 327 331 # login POST dicts 328 332 self.super_login = { … … 584 588 self.failUnlessEqual(logged.object_id, u'1') 585 589 self.client.get('/test_admin/admin/logout/') 586 590 591 def testDeleteViewWithMultipleForeignKeysToSameTable(self): 592 """Regression for #6191.""" 593 red = Color.objects.create(value='Red') 594 thing1 = MulticoloredThing.objects.create(title='Thing 1', background_color=red) 595 self.client.get('/test_admin/admin/') 596 self.client.post('/test_admin/admin/', self.deleteuser_login) 597 response = self.client.get('/test_admin/admin/admin_views/color/%d/delete/' % red.id) 598 self.assertContains(response, 'admin_views/multicoloredthing/%d/' % thing1.id) 599 587 600 class AdminViewStringPrimaryKeyTest(TestCase): 588 601 fixtures = ['admin-views-users.xml', 'string-primary-key.xml'] 589 602 … … 1605 1618 "Check the never-cache status of the Javascript i18n view" 1606 1619 response = self.client.get('/test_admin/jsi18n/') 1607 1620 self.failUnlessEqual(get_max_age(response), None) 1608 -
tests/regressiontests/admin_views/models.py
138 138 class ThingAdmin(admin.ModelAdmin): 139 139 list_filter = ('color',) 140 140 141 class MulticoloredThing(models.Model): 142 title = models.CharField(max_length=20) 143 foreground_color = models.ForeignKey(Color, related_name='thing_foreground', blank=True, null=True) 144 background_color = models.ForeignKey(Color, related_name='thing_background', blank=True, null=True) 145 def __unicode__(self): 146 return self.title 147 141 148 class Fabric(models.Model): 142 149 NG_CHOICES = ( 143 150 ('Textured', ( … … 426 433 admin.site.register(ModelWithStringPrimaryKey) 427 434 admin.site.register(Color) 428 435 admin.site.register(Thing, ThingAdmin) 436 admin.site.register(MulticoloredThing) 429 437 admin.site.register(Person, PersonAdmin) 430 438 admin.site.register(Persona, PersonaAdmin) 431 439 admin.site.register(Subscriber, SubscriberAdmin)