To complete the story, in case someone finds this in the future, I
ended up with the following which at the time of this writing seems to
work:

class MyNullBooleanField(models.NullBooleanField):
    """Designed to work with how Microsoft Access stores booleans as
-1 and 0 into MySQL.
    The to_python function was taken from the Django modeld with
addition of -1 for true."""
    __metaclass__ = models.SubfieldBase
    def to_python(self,value):
        if value in (True, False):
            return bool(value)
        if value in ('None',):
            return None
        if value in ('t', 'True', '1', '-1', 1, -1):
            return True
        if value in ('f', 'False', '0', 0):
            return False
        if value is None:
            return None

The whole to_python function was taken from the standard definition
from the Django library.  My simple first draft wasn't complete
enough. I found that i needed to test for the integers 0,1, and -1 in
addition to their string equivalents in if value in "('t', 'True',
'1', '-1', 1, -1)" and "if value in ('f', 'False', '0', 0)". With that
change it appears to handle the boolean data stored into MySQL as
written by the Microsoft Access forms on the front end.

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

Reply via email to