#14638: to_python howto documentation improvement
------------------------------------+---------------------------------------
          Reporter:  maraujop       |         Owner:  nobody                 
            Status:  new            |     Milestone:                         
         Component:  Documentation  |       Version:  SVN                    
        Resolution:                 |      Keywords:  to_python, model, field
             Stage:  Accepted       |     Has_patch:  0                      
        Needs_docs:  0              |   Needs_tests:  0                      
Needs_better_patch:  0              |  
------------------------------------+---------------------------------------
Changes (by maraujop):

 * cc: muchoch...@gmail.com (added)

Comment:

 I don't think docs are correct or I'm missing something. I have tried
 different subclasses and in all of them {{{ to_python }}} gets called
 before assigning a value to the field. {{{ to_python }}} is the method in
 charge of converting the value to the expected python type to see if it
 can be assigned.

 I have put prints in my own DecimalField to see when they were being
 called. I haven't seen {{{ to_pỳthon }}} been called to convert data
 returned by the DB never. Here is the code of my subclass:

 {{{
 class Test(models.DecimalField):
     def to_python(self, value):
         print "to_python"
         if value is None:
             return value
         try:
             return decimal.Decimal(value)

         except decimal.InvalidOperation:
             raise
 exceptions.ValidationError(self.error_messages['invalid'])

     def __unicode__(self):
         print "__unicode__"
         return self.to_python()
 }}}

 The code is the same used in DecimalField. So I'm doing something wrong or
 {{{ to_python }}} does not work as the docs say.

 Thanks, regards

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14638#comment:2>
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-upda...@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