Ticket #2199: related.diff

File related.diff, 3.0 KB (added by parlar@…, 18 years ago)

[patch] Corrects the error

  • contrib/admin/views/main.py

     
    112112    def __init__(self, field, field_mapping, original):
    113113        self.field = field
    114114        self.original = original
     115        print "NAMES", list(self.field.get_manipulator_field_names(''))
    115116        self.form_fields = [field_mapping[name] for name in self.field.get_manipulator_field_names('')]
    116117        self.element_id = self.form_fields[0].get_id()
    117118        self.has_label_first = not isinstance(self.field, models.BooleanField)
     
    462463        opts_seen.append(related.opts)
    463464        rel_opts_name = related.get_accessor_name()
    464465        has_related_objs = False
    465         for sub_obj in getattr(obj, rel_opts_name).all():
     466        rel_objs = getattr(obj, rel_opts_name, None)
     467        if rel_objs:
    466468            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)))), []])
     469
     470        if has_related_objs:
     471            for sub_obj in rel_objs.all():
     472                if related.field.rel.edit_inline or not related.opts.admin:
     473                    # Don't display link to edit, because it either has no
     474                    # admin or is edited inline.
     475                    nh(deleted_objects, current_depth, [_('One or more %(fieldname)s in %(name)s: %(obj)s') % \
     476                        {'fieldname': related.field.verbose_name, 'name': related.opts.verbose_name, 'obj': escape(str(sub_obj))}, []])
     477                else:
     478                    # Display a link to the admin page.
     479                    nh(deleted_objects, current_depth, [
     480                        (_('One or more %(fieldname)s in %(name)s:') % {'fieldname': related.field.verbose_name, 'name':related.opts.verbose_name}) + \
     481                        (' <a href="../../../../%s/%s/%s/">%s</a>' % \
     482                            (related.opts.app_label, related.opts.module_name, sub_obj._get_pk_val(), escape(str(sub_obj)))), []])
    478483        # If there were related objects, and the user doesn't have
    479484        # permission to change them, add the missing perm to perms_needed.
    480485        if related.opts.admin and has_related_objs:
Back to Top