Django

Code

Changeset 3307

Show
Ignore:
Timestamp:
07/09/06 23:16:26 (2 years ago)
Author:
adrian
Message:

Fixed #2301 -- Added list_display_links option to 'class Admin', which regulates which fields in the change list have links. Thanks, kilian

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r3285 r3307  
    7373    Russell Keith-Magee <freakboy@iinet.net.au> 
    7474    Garth Kidd <http://www.deadlybloodyserious.com/> 
     75    kilian <kilian.cavalotti@lip6.fr> 
    7576    Sune Kirkeby <http://ibofobi.dk/> 
    7677    Cameron Knight (ckknight) 
  • django/trunk/django/contrib/admin/templatetags/admin_list.py

    r3124 r3307  
    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) 
  • django/trunk/django/core/management.py

    r3276 r3307  
    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)): 
  • django/trunk/django/db/models/options.py

    r3201 r3307  
    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): 
     
    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 
  • django/trunk/docs/model-api.txt

    r3189 r3307  
    12251225                  return self.birthday.strftime('%Y')[:3] + "0's" 
    12261226              decade_born_in.short_description = 'Birth decade' 
     1227 
     1228``list_display_links`` 
     1229---------------------- 
     1230 
     1231Set ``list_display_links`` to control which fields in ``list_display`` should 
     1232be linked to the "change" page for an object. 
     1233 
     1234By default, the change list page will link the first column -- the first field 
     1235specified in ``list_display`` -- to the change page for each item. But 
     1236``list_display_links`` lets you change which columns are linked. Set 
     1237``list_display_links`` to a list or tuple of field names (in the same format as 
     1238``list_display``) to link. 
     1239 
     1240``list_display_links`` can specify one or many field names. As long as the 
     1241field names appear in ``list_display``, Django doesn't care how many (or how 
     1242few) fields are linked. The only requirement is: If you want to use 
     1243``list_display_links``, you must define ``list_display``. 
     1244 
     1245In this example, the ``first_name`` and ``last_name`` fields will be linked on 
     1246the change list page:: 
     1247 
     1248    class Admin: 
     1249        list_display = ('first_name', 'last_name', 'birthday') 
     1250        list_display_links = ('first_name', 'last_name') 
     1251 
     1252Finally, note that in order to use ``list_display_links``, you must define 
     1253``list_display``, too. 
    12271254 
    12281255``list_filter``