Ticket #6191: admin_deleted_objects.patch
File admin_deleted_objects.patch, 3.4 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/views/main.py
diff -r bb34df2ffc54 -r aa4e58e3a068 django/contrib/admin/views/main.py
a b def _get_deleted_objects(deleted_objects 419 419 return # Avoid recursing too deep. 420 420 opts_seen = [] 421 421 for related in opts.get_all_related_objects(): 422 if related.opts in opts_seen: 422 rel_opts_name = related.get_accessor_name() 423 if rel_opts_name in opts_seen: 423 424 continue 424 opts_seen.append(related.opts) 425 rel_opts_name = related.get_accessor_name() 425 opts_seen.append(rel_opts_name) 426 426 if isinstance(related.field.rel, models.OneToOneRel): 427 427 try: 428 428 sub_obj = getattr(obj, rel_opts_name) … … def _get_deleted_objects(deleted_objects 467 467 if not user.has_perm(p): 468 468 perms_needed.add(related.opts.verbose_name) 469 469 for related in opts.get_all_related_many_to_many_objects(): 470 if related.opts in opts_seen: 470 rel_opts_name = related.get_accessor_name() 471 if rel_opts_name in opts_seen: 471 472 continue 472 opts_seen.append(related.opts) 473 rel_opts_name = related.get_accessor_name() 473 opts_seen.append(rel_opts_name) 474 474 has_related_objs = False 475 475 476 476 # related.get_accessor_name() could return None for symmetrical relationships -
new file tests/regressiontests/admin_deleted_objects/models.py
diff -r bb34df2ffc54 -r aa4e58e3a068 tests/regressiontests/admin_deleted_objects/models.py
- + 1 from django.db import models 2 3 class Staff(models.Model): 4 name = models.CharField(max_length=100) 5 6 def __unicode___(self): 7 return self.name 8 9 def __str__(self): 10 return self.name.encode('utf-8') 11 12 class Project(models.Model): 13 name = models.CharField(max_length=100) 14 team_leader = models.ForeignKey(Staff, related_name='lead_projects') 15 contact_person = models.ForeignKey(Staff, related_name='contact_projects') 16 17 def __unicode___(self): 18 return self.name 19 20 def __str__(self): 21 return self.name.encode('utf-8') -
new file tests/regressiontests/admin_deleted_objects/tests.py
diff -r bb34df2ffc54 -r aa4e58e3a068 tests/regressiontests/admin_deleted_objects/tests.py
- + 1 try: 2 set 3 except NameError: 4 from sets import Set as set # Python 2.3 fallback 5 6 __test__ = {'tests': r""" 7 >>> from regressiontests.admin_deleted_objects.models import * 8 >>> from django.contrib.admin.views.main import _get_deleted_objects 9 >>> from django.contrib.auth.models import AnonymousUser 10 11 >>> def print_deleted_objects(obj): 12 ... deleted_objects = [] 13 ... user = AnonymousUser() 14 ... perms_needed = set() 15 ... _get_deleted_objects(deleted_objects, perms_needed, user, obj, obj.__class__._meta, 0) 16 ... print deleted_objects 17 18 >>> adam = Staff.objects.create(name=u'Adam') 19 >>> sue = Staff.objects.create(name=u'Sue') 20 >>> project = Project.objects.create(name=u'World Domination', team_leader=adam, contact_person=sue) 21 22 >>> print_deleted_objects(adam) 23 [[u'Project: World Domination', []]] 24 25 >>> print_deleted_objects(sue) 26 [[u'Project: World Domination', []]] 27 28 """}