Ticket #2199: related_fix.diff

File related_fix.diff, 2.6 KB (added by parlar@…, 18 years ago)

[patch] Fixes a small problem with the original path

  • django/contrib/admin/views/main.py

     
    462462        opts_seen.append(related.opts)
    463463        rel_opts_name = related.get_accessor_name()
    464464        has_related_objs = False
    465         for sub_obj in getattr(obj, rel_opts_name).all():
     465        rel_objs = getattr(obj, rel_opts_name, None)
     466        if rel_objs:
    466467            has_related_objs = True
    467             if related.field.rel.edit_inline or not related.opts.admin:
    468                 # Don't display link to edit, because it either has no
    469                 # admin or is edited inline.
    470                 nh(deleted_objects, current_depth, [_('One or more %(fieldname)s in %(name)s: %(obj)s') % \
    471                     {'fieldname': related.field.verbose_name, 'name': related.opts.verbose_name, 'obj': escape(str(sub_obj))}, []])
    472             else:
    473                 # Display a link to the admin page.
    474                 nh(deleted_objects, current_depth, [
    475                     (_('One or more %(fieldname)s in %(name)s:') % {'fieldname': related.field.verbose_name, 'name':related.opts.verbose_name}) + \
    476                     (' <a href="../../../../%s/%s/%s/">%s</a>' % \
    477                         (related.opts.app_label, related.opts.module_name, sub_obj._get_pk_val(), escape(str(sub_obj)))), []])
     468
     469        if has_related_objs:
     470            for sub_obj in rel_objs.all():
     471                if related.field.rel.edit_inline or not related.opts.admin:
     472                    # Don't display link to edit, because it either has no
     473                    # admin or is edited inline.
     474                    nh(deleted_objects, current_depth, [_('One or more %(fieldname)s in %(name)s: %(obj)s') % \
     475                        {'fieldname': related.field.verbose_name, 'name': related.opts.verbose_name, 'obj': escape(str(sub_obj))}, []])
     476                else:
     477                    # Display a link to the admin page.
     478                    nh(deleted_objects, current_depth, [
     479                        (_('One or more %(fieldname)s in %(name)s:') % {'fieldname': related.field.verbose_name, 'name':related.opts.verbose_name}) + \
     480                        (' <a href="../../../../%s/%s/%s/">%s</a>' % \
     481                            (related.opts.app_label, related.opts.module_name, sub_obj._get_pk_val(), escape(str(sub_obj)))), []])
    478482        # If there were related objects, and the user doesn't have
    479483        # permission to change them, add the missing perm to perms_needed.
    480484        if related.opts.admin and has_related_objs:
Back to Top