#3287: [patch] Model methods in the change list can have checkmark icons by
decorating with boolean=True
--------------------------------+-------------------------------------------
 Reporter:  [EMAIL PROTECTED]  |       Owner:  adrian                           
       
     Type:  enhancement         |      Status:  new                             
        
 Priority:  normal              |   Milestone:                                  
        
Component:  Admin interface     |     Version:                                  
        
 Severity:  normal              |    Keywords:  admin, list_display, boolean, 
checkmarks
--------------------------------+-------------------------------------------
 Model methods that return true or false show up as 'True' or 'False' in
 the admin if you put them in the list_display. Which isn't anywhere near
 as nice as the checkmark icons that BooleanFields get. If you want to get
 them yourself you have to do this:
 
 
 {{{
     def is_current(self):
         from django.conf import settings
         current = self.start_date <= datetime.now() and self.end_date >=
 datetime.now()
         BOOLEAN_MAPPING = {True: 'yes', False: 'no', None: 'unknown'}
         result_repr = '<img src="%simg/admin/icon-%s.gif" alt="%s" />' %
 (settings.ADMIN_MEDIA_PREFIX, BOOLEAN_MAPPING[current], current)
         return result_repr
     is_current.allow_tags = True
 
 }}}
 
 Which is messy and brittle.
 
 This patch lets you simply decorate the method with boolean=True and it
 works just like a booleanField
 
 {{{
     def is_current(self):
         return self.start_date <= datetime.now() and self.end_date >=
 datetime.now()
     is_current.boolean = True
 }}}
 
 This is my first patch, so please look it over and advise if there is any
 way the styling could be improved to be more pythonic, or more djangonic.
 :)
 
 I couldn't find any current tests that cover items_for_result() so I
 wasn't sure how to add tests for this. I'm pretty sure I could add to an
 existing test set, but am unsure how to go about creating a full new one.
 
 That said, the change is pretty trivial.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3287>
Django <http://code.djangoproject.org/>
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to