Ticket #6191: newforms-admin_deleted_objects.patch
File newforms-admin_deleted_objects.patch, 3.5 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/util.py
diff -r c2b38236b415 -r 405f480d7443 django/contrib/admin/util.py
a b def get_deleted_objects(deleted_objects, 19 19 opts_seen = [] 20 20 for related in opts.get_all_related_objects(): 21 21 has_admin = related.__class__ in admin_site._registry 22 if related.opts in opts_seen: 22 rel_opts_name = related.get_accessor_name() 23 if rel_opts_name in opts_seen: 23 24 continue 24 opts_seen.append(related.opts) 25 rel_opts_name = related.get_accessor_name() 25 opts_seen.append(rel_opts_name) 26 26 if isinstance(related.field.rel, models.OneToOneRel): 27 27 try: 28 28 sub_obj = getattr(obj, rel_opts_name) … … def get_deleted_objects(deleted_objects, 68 68 perms_needed.add(related.opts.verbose_name) 69 69 for related in opts.get_all_related_many_to_many_objects(): 70 70 has_admin = related.__class__ in admin_site._registry 71 if related.opts in opts_seen: 71 rel_opts_name = related.get_accessor_name() 72 if rel_opts_name in opts_seen: 72 73 continue 73 opts_seen.append(related.opts) 74 rel_opts_name = related.get_accessor_name() 74 opts_seen.append(rel_opts_name) 75 75 has_related_objs = False 76 76 77 77 # related.get_accessor_name() could return None for symmetrical relationships -
new file tests/regressiontests/admin_deleted_objects/models.py
diff -r c2b38236b415 -r 405f480d7443 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 c2b38236b415 -r 405f480d7443 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.util import get_deleted_objects 9 >>> from django.contrib.auth.models import AnonymousUser 10 >>> from django.contrib.admin.sites import AdminSite 11 12 >>> admin_site = AdminSite() 13 14 >>> def print_deleted_objects(obj): 15 ... deleted_objects = [] 16 ... user = AnonymousUser() 17 ... perms_needed = set() 18 ... get_deleted_objects(deleted_objects, perms_needed, user, obj, obj.__class__._meta, 0, admin_site) 19 ... print deleted_objects 20 21 >>> adam = Staff.objects.create(name=u'Adam') 22 >>> sue = Staff.objects.create(name=u'Sue') 23 >>> project = Project.objects.create(name=u'World Domination', team_leader=adam, contact_person=sue) 24 25 >>> print_deleted_objects(adam) 26 [[u'Project: World Domination', []]] 27 28 >>> print_deleted_objects(sue) 29 [[u'Project: World Domination', []]] 30 31 """}