I'm adapting a legacy database for use with Django and I've come across a problem I haven't been able to solve!
The database has ForeignKey fields which are sometimes 0, meaning there is no related row in the other table. If this database used NULL instead of 0 then I could use ForeignKey(Other, null=True) and all would work fine, but it doesn't and I can't change it. I've tried lots of different ways of making an adaptor to change the 0 into a None when read from the database but I haven't made it work (or even get called!) yet - can anyone give me a clue? I'm trying to subclass ForeignKey but none of the methods I override (except __init__) seem to ever get called! Eg ... class ForeignKeyWithZeros(models.ForeignKey): """ A ForeignKey, but when the id is 0 the relation is considered to be NULL Use with null=True """ def __get__(self, instance, *args, **kwargs): # never gets called print "Instance %r " % instance def to_python(self, value): # never gets called print "to_python %r" % value I'm using svn of few days ago. Thanks Nick -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---