Ticket #2301: django.admin.list_display_links.patch

File django.admin.list_display_links.patch, 3.3 KB (added by kilian <kilian.cavalotti@…>, 18 years ago)

Patch adding display_fields_links option

  • django/db/models/options.py

     
    199199        return self._field_types[field_type]
    200200
    201201class AdminOptions(object):
    202     def __init__(self, fields=None, js=None, list_display=None, list_filter=None,
     202    def __init__(self, fields=None, js=None, list_display=None, list_display_links=None, list_filter=None,
    203203        date_hierarchy=None, save_as=False, ordering=None, search_fields=None,
    204204        save_on_top=False, list_select_related=False, manager=None, list_per_page=100):
    205205        self.fields = fields
    206206        self.js = js or []
    207207        self.list_display = list_display or ['__str__']
     208        self.list_display_links = list_display_links or []
    208209        self.list_filter = list_filter or []
    209210        self.date_hierarchy = date_hierarchy
    210211        self.save_as, self.ordering = save_as, ordering
  • django/core/management.py

     
    936936                        else:
    937937                            if isinstance(f, models.ManyToManyField):
    938938                                e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn)
     939                # list_display_links
     940                if opts.admin.list_display_links and not opts.admin.list_display:
     941                    e.add(opts, '"admin.list_display" must be defined for "admin.list_display_links" to be used.')
     942                if not isinstance(opts.admin.list_display_links, (list, tuple)):
     943                    e.add(opts, '"admin.list_display_links", if given, must be set to a list or tuple.')
     944                else:
     945                    for fn in opts.admin.list_display_links:
     946                        try:
     947                            f = opts.get_field(fn)
     948                        except models.FieldDoesNotExist:
     949                            e.add(opts, '"admin.list_filter" refers to %r, which isn\'t a field.' % fn)
     950                        if fn not in opts.admin.list_display:
     951                            e.add(opts, '"admin.list_display_links" refers to %r, which is not defined in "admin.list_display".' % fn)
    939952                # list_filter
    940953                if not isinstance(opts.admin.list_filter, (list, tuple)):
    941954                    e.add(opts, '"admin.list_filter", if given, must be set to a list or tuple.')
  • django/contrib/admin/templatetags/admin_list.py

     
    165165                result_repr = escape(str(field_val))
    166166        if result_repr == '':
    167167            result_repr = '&nbsp;'
    168         if first: # First column is a special case
     168        # If list_display_links not defined, add the link tag to the first field
     169        if (first and not cl.lookup_opts.admin.list_display_links) or field_name in cl.lookup_opts.admin.list_display_links:
    169170            first = False
    170171            url = cl.url_for_result(result)
    171172            result_id = str(getattr(result, pk)) # str() is needed in case of 23L (long ints)
Back to Top