Re: Redefine True and False for Boolean and/or NullBoolean Fields?
Tom,
Thanks ... Can I get a bit more of your brain power. I'm struggling
with understanding the custom-model-fields document sufficient to
allow me to do it.
At the top of the models.py files, I put in:
class MyNullBooleanField(models.NullBooleanField):
"""Designed to work with how Microsoft Access stores booleans as
-1 and 0 into MySQL"""
__metaclass__ = models.SubfieldBase
def to_python(self,value):
if value is None: return
if value == 0:
return False
else:
return True
down further in that file, as a first test of this new field, for the
table/class where I want to use it:
class MemberAddress(models.Model):
member=models.ForeignKey(Member,related_name='addresses',
db_column='memberid')
city = models.CharField(max_length=50, db_column='city',
blank=True)
forinvoice=models.MyNullBooleanField(null=True,
db_column='forinvoice', blank=True)
When I run the code I get the error on the above "forinvoice" line:
AttributeError: 'module' object has no attribute 'MyNullBooleanField'
I was assuming that by defining the new custom field at the top of the
models.py file, it would work. I can't find anything in the custom-
model-fields doc which says "where" to put this custom definition. I
just assumed they intended it to go into models.py
What am i doing wrong? Thanks!!
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home