Ticket #6191: newforms-admin_deleted_objects.patch

File newforms-admin_deleted_objects.patch, 3.5 KB (added by nicklane, 17 years ago)

Patch agains newforms-admin

  • django/contrib/admin/util.py

    diff -r c2b38236b415 -r 405f480d7443 django/contrib/admin/util.py
    a b def get_deleted_objects(deleted_objects,  
    1919    opts_seen = []
    2020    for related in opts.get_all_related_objects():
    2121        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:
    2324            continue
    24         opts_seen.append(related.opts)
    25         rel_opts_name = related.get_accessor_name()
     25        opts_seen.append(rel_opts_name)
    2626        if isinstance(related.field.rel, models.OneToOneRel):
    2727            try:
    2828                sub_obj = getattr(obj, rel_opts_name)
    def get_deleted_objects(deleted_objects,  
    6868                    perms_needed.add(related.opts.verbose_name)
    6969    for related in opts.get_all_related_many_to_many_objects():
    7070        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:
    7273            continue
    73         opts_seen.append(related.opts)
    74         rel_opts_name = related.get_accessor_name()
     74        opts_seen.append(rel_opts_name)
    7575        has_related_objs = False
    7676
    7777        # 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
    - +  
     1from django.db import models
     2
     3class 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
     12class 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
    - +  
     1try:
     2    set
     3except 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"""}
Back to Top