#12546: Definining __len__ on a model object breaks it's serialization
-------------------------------------+--------------------------------------
          Reporter:  casbon          |         Owner:  nobody
            Status:  new             |     Milestone:        
         Component:  Core framework  |       Version:  1.1   
        Resolution:                  |      Keywords:        
             Stage:  Unreviewed      |     Has_patch:  0     
        Needs_docs:  0               |   Needs_tests:  0     
Needs_better_patch:  0               |  
-------------------------------------+--------------------------------------
Changes (by claudep):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 Been confronted to the same issue today. On one side, the object can
 workaround this by defining the {{{__nonzero__}}} method (see
 [http://docs.python.org/reference/datamodel.html#object.__len__]). On the
 other side, the test here is not to know if the object evaluates to True
 or False, but if it can be queried for the attribute.

 What about:
 {{{
 def _get_val_from_obj(self, obj):
     return getattr(obj, self.get_attname(), self.get_default())
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12546#comment:1>
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 [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