Ticket #6191: multiple-fk-delete-view.diff

File multiple-fk-delete-view.diff, 4.1 KB (added by shields@…, 15 years ago)
  • django/contrib/admin/util.py

     
    8585    nh = _nest_help # Bind to local variable for performance
    8686    if current_depth > 16:
    8787        return # Avoid recursing too deep.
    88     opts_seen = []
    8988    for related in opts.get_all_related_objects():
    9089        has_admin = related.model in admin_site._registry
    91         if related.opts in opts_seen:
    92             continue
    93         opts_seen.append(related.opts)
    9490        rel_opts_name = related.get_accessor_name()
    9591        if isinstance(related.field.rel, models.OneToOneRel):
    9692            try:
     
    148144                    perms_needed.add(related.opts.verbose_name)
    149145    for related in opts.get_all_related_many_to_many_objects():
    150146        has_admin = related.model in admin_site._registry
    151         if related.opts in opts_seen:
    152             continue
    153         opts_seen.append(related.opts)
    154147        rel_opts_name = related.get_accessor_name()
    155148        has_related_objs = False
    156149
  • tests/regressiontests/admin_views/tests.py

     
    1818    ExternalSubscriber, FooAccount, Gallery, ModelWithStringPrimaryKey, \
    1919    Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \
    2020    Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \
    21     Category
     21    Category, Color, MulticoloredThing
    2222
    2323try:
    2424    set
     
    323323
    324324        delete_user.user_permissions.add(get_perm(Section,
    325325            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()))
    326330
    327331        # login POST dicts
    328332        self.super_login = {
     
    584588        self.failUnlessEqual(logged.object_id, u'1')
    585589        self.client.get('/test_admin/admin/logout/')
    586590
     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
    587600class AdminViewStringPrimaryKeyTest(TestCase):
    588601    fixtures = ['admin-views-users.xml', 'string-primary-key.xml']
    589602
     
    16051618        "Check the never-cache status of the Javascript i18n view"
    16061619        response = self.client.get('/test_admin/jsi18n/')
    16071620        self.failUnlessEqual(get_max_age(response), None)
    1608 
  • tests/regressiontests/admin_views/models.py

     
    138138class ThingAdmin(admin.ModelAdmin):
    139139    list_filter = ('color',)
    140140
     141class 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
    141148class Fabric(models.Model):
    142149    NG_CHOICES = (
    143150        ('Textured', (
     
    426433admin.site.register(ModelWithStringPrimaryKey)
    427434admin.site.register(Color)
    428435admin.site.register(Thing, ThingAdmin)
     436admin.site.register(MulticoloredThing)
    429437admin.site.register(Person, PersonAdmin)
    430438admin.site.register(Persona, PersonaAdmin)
    431439admin.site.register(Subscriber, SubscriberAdmin)
Back to Top