#5863: list_display does not allow functions of referenced objects
-------------------------------------+-------------------------------------
               Reporter:  Beat       |        Owner:  nobody
  Bolli <me+django@…>                |       Status:  closed
                   Type:             |    Component:  contrib.admin
  Uncategorized                      |     Severity:  Normal
              Milestone:             |     Keywords:  list_display
                Version:  SVN        |    Has patch:  1
             Resolution:  wontfix    |  Needs tests:  0
           Triage Stage:  Design     |
  decision needed                    |
    Needs documentation:  1          |
Patch needs improvement:  1          |
-------------------------------------+-------------------------------------

Comment (by lukeplant):

 @brillgen:

 It's difficult to believe there would be much difference between the two
 methods if you are using 'select_related' correctly (and we don't want to
 complicate the logic for select_related any further).

 Also, note that you could easily write a function that would eliminate the
 boilerplate, if it is really boilerplate that conforms to a common
 pattern. Untested code:

 {{{
 #!python

 def foreign_field(field_name):
     def accessor(obj):
         val = obj
         for part in field_name.split('__'):
             val = getattr(val, part)
         return val
     accessor.__name__ = field_name
     return accessor

 ff = foreign_field

 class MyAdmin(ModelAdmin):

     list_display = [ff('foreign_key__related_fieldname1'),
                     ff('foreign_key__related_fieldname2')]
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/5863#comment:32>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to